0

On http://www.elitedeafpoker.com/dev/poker-players.html - AJAX loads JSON data into a table and Im trying to add some classes to display background-color on only two tags seperately and center the texts, but it didnt work for me and I removed it. I need the table to look like this - http://www.elitedeafpoker.com/dev/img/table-example.jpg

Javascript

$(document).ready(function() {
    $.getJSON("js/dataPokerPlayers.json", function(data) {
        $.each(data, function(i, data){
            $(".tableData tbody").append("<tr><td>" + data.rank + "</td><td>" + data.name + "</td><td>" + data.earnings + "</td><td>" + data.points + "</td><td>" + data.totalearnings + "</td></tr>");
        });
    });
});
2
  • 1
    Hold on a second, you are developing a webpage for a pokerOnline but you don't know how to add a css selector to a <td> nor to text-align:center ??? Commented Apr 18, 2013 at 18:36
  • Yes, I said I tried to add "class="centertext" to center the texts, but it didnt work in javascript. Evan put class=\"center\" for me, that is fairly new to me to put two \s. in <td> By the way, its not an online game. Commented Apr 18, 2013 at 18:49

1 Answer 1

1

You can add in class="center" to the <td> elements that you want to be centered and then use a CSS selector to style those td's with the center class name.

jQuery:

$(document).ready(function() {
    $.getJSON("js/dataPokerPlayers.json", function(data) {
        $.each(data, function(i, data){
            $(".tableData tbody").append("<tr><td>" + data.rank + "</td><td>" + data.name + "</td><td class=\"center\">" + data.earnings + "</td><td class=\"center\">" + data.points + "</td><td>" + data.totalearnings + "</td></tr>");
        });
    });
});

CSS:

.center{
    text-align: center;
}
Sign up to request clarification or add additional context in comments.

4 Comments

It looks like you're also trying to change the background color of alternating rows. You can do you with this css: .tableData tr:nth-child(even) { background-color: #000000; }
Thank you Evan! mchail that is what I need, but it didnt work for me.
and that will close the question? I still have one more to go to fix the alernating row background-color nth-child(even) that didnt work for me
@Christian That wasn't part of the original question. Honestly, you should close this one and open up another one with the background colors. However, look up "zebra table layout" and you'll find your answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.