Home > front end >  jQuery how to replace :last selector if I need its children?
jQuery how to replace :last selector if I need its children?

Time:02-16

I am upgrading my code for the latest jQuery, but I stumbled into a problem with deprecated :last selector. In most cases, all I needed to do was to delete it and slap .last() after, but I have a problem with this:

$('#someId tr:last textarea').each(function(){
    //some code
});

where :last is not the ultimate thing I want to select. I don't even know how to form the google question for this. How can I approach this?

CodePudding user response:

You can still continue selecting after .last() (that's basic functionality of jquery, I advice to read up on it if you want to continue to use it) or simply use css selector :last-child

$('#someId tr:last-child textarea').each(function(){
    //some code
});

or

$('#someId tr').last().find('textarea').each(function(){
    //some code
});
  • Related