Reputation: 347
Given this HTML table:
<table id="#myTable">
<tr id="#row123"><td>Content</td></tr>
</table>
Add in a row with jquery:
$('#myTable').prepend('<tr id="#row456"><td>More content</td></tr>');
Later on I want to select the #row456
row that was created. How do I do that?
$('#row456')
does not work?
Upvotes: 0
Views: 29
Reputation: 382102
Remove the #
from the id when creating the elements in HTML:
$('#myTable').prepend('<tr id="row456"><td>More content</td></tr>');
#someid
is the syntax of a jQuery selector selecting the element having someid
as id (reference). You also have the same syntax for selection by id in CSS.
Upvotes: 3
Reputation:
Don't use #
before id
$('#myTable').prepend('<tr id="row456"><td>More content</td></tr>');
Also your HTML
<table id="myTable">
<tr id="row123"><td>Content</td></tr>
</table>
Upvotes: 2