I have a div with a span
<div id="div1">
<span class="">hello</span>
</div>
When i click on div i want to change the class of only first span element of the div
$('#div1').click(function() {
// ... check if first span element inside the div .. if there and change the class..
});
The :first selector selects the first element.
How to move span element with image right to the div tag? position: absolute removes the floating possibility. Use right:0 if you need to have it absolutely positioned, but also set the parent div to position: relative for it to work.
Multiple answers valid. My approach:
$('#div1').click(function() {
$(this).find('span').first().attr('class','newClassName');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With