I have a list of items inside a table. I have decided to change the table structure a bit so that things look more organized, and added some more <tr>
's in.
What happened is that my jQuery code doesn't work well anymore.
I have that piece of code:
$(':input:not(.ajax-confirmed)').each(function(m,r){
var $row = $(r).closest('tr');
$row.remove();
});
I would simply like to select the closest <tr>
and signify it with an additional parameter, I thought maybe a class, so that I know what kind of <tr>
I am removing.
How can I select the closest tr with a specific class name?
I have a list of items inside a table. I have decided to change the table structure a bit so that things look more organized, and added some more <tr>
's in.
What happened is that my jQuery code doesn't work well anymore.
I have that piece of code:
$(':input:not(.ajax-confirmed)').each(function(m,r){
var $row = $(r).closest('tr');
$row.remove();
});
I would simply like to select the closest <tr>
and signify it with an additional parameter, I thought maybe a class, so that I know what kind of <tr>
I am removing.
How can I select the closest tr with a specific class name?
Share Improve this question edited Oct 9, 2011 at 12:44 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Oct 9, 2011 at 12:42 TedTed 3,87315 gold badges59 silver badges100 bronze badges 1- Show your relevant HTML structure. – Rob W Commented Oct 9, 2011 at 12:45
3 Answers
Reset to default 3This should work, depending on your HTML structure:
$(':input:not(.ajax-confirmed)').each(function(m,r){
var $row = $(r).closest('tr.className');
$row.remove();
});
Hope this helps!
If you look in the documentation, you will find this example:
$('li.item-a').closest('ul', listItemII)
.css('background-color', 'red');
The second parameter coult be a class name. So in your example, just add something like this:
var $row = $(r).closest('tr', 'some class name');
"I would simply like to select the closest "
.closest('tr')
or
.closest('.myclass')