Aller au contenu | Aller au menu | Aller à la recherche


jQuery find

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');

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

Fil des commentaires de ce billet