jQuery find
Par PlaceOweb le dimanche, avril 17 2016, 21:55 - Javascript - Lien permanent
How to use selectors on a jQuery Object ?
<body> <div id="my_html_id_root"> <p><span id="my_html_id">Hello</span>, how are you?</p> <p>Me? I'm <span>good</span>.</p> </div> <script> // instructions below </script> </body>
$('*').css( "color", "blue" ); // all elements $('#my_html_id').css( "color", "red" ); // or $myJqObject = $('#my_html_id_root'); $myJqObject.find( "span" ).css( "background-color", "yellow" );
Hello, how are you?
Me? I'm good.
Tips: if your html element contains brackets, you need to escape them
$('my_html_id_\\[' + id_of_my_index + '\\]).find( "span" ).css( "background-color", "yellow" );
For exemple, last tr of a table :
$('#compareTable tr').last().css('border', '0'); // or $('#compareTable tr:last-child').css('border', '0'); // or (for better performance) $('#compareTable tr').filter(':last').css('border', '0');
- Selectors
- .find()
- jQuery Fundamentals - A guide to the basics of jQuery : jQuery Basics, Traversing & Manipulating