Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jQuery how to replace :last selector if I need its children?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading