0

I've been trying all night to get a dynamically created set of table to change their class.

Normally JQuery will let you do this:

$('table tbody tr').click(function () {
    // remove clickedRow class from all same level rows?
    $(this).addClass('clickedRow');
});

I want to apply something similar but to a specific but dynamically created id. I've tried

$(idname 'tbody tr')

and

$('idname tbody tr')

but haven't been able to find a work around.

Is there a solution?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Tony_Wh
  • 41
  • 1
  • 5

2 Answers2

0

You have to put # before IDs. And you have to use proper Javascript string concatenation syntax.

$("#" + idname + " tbody tr")

However, if you want to bind a handler to elements that will be created dynamically, it's usually better to use delegation. See

Event binding on dynamically created elements?

Community
  • 1
  • 1
Barmar
  • 669,327
  • 51
  • 454
  • 560
0

You need the ID selector http://api.jquery.com/id-selector/

$('#idname tbody tr')

or

$('#' + idname + ' tbody tr')
Cameron
  • 51
  • 2