salmon eater
salmon eater

Reputation: 49

Passing a variable to a jquery selector

This works:

function rowColors(){
     $("table#remotes th").css("background-color", "#202020");
     $("table#remotes tr").css("background-color", "#484848");
     $("table#remotes tr:visible:odd").css("background-color", "#333333");
 }

How can I make this work with a variable table id? This doesn't work:

function rowColors(tblid){
    $("table#"+tblid+" th").css("background-color", "#202020");
    $("table#"+tblid+" tr").css("background-color", "#484848");
    $("table#"+tblid+" tr:visible:odd").css("background-color", "#333333");
}

rowColors(remotes);

Upvotes: 0

Views: 45

Answers (1)

epascarello
epascarello

Reputation: 207501

Maybe because remotes is a variable and not a string

rowColors('remotes');

Upvotes: 6

Related Questions