jquery - how is multiple selection working in this example?
- by hatorade
The relevant snippet of HTML:
<span class="a">
<div class="fieldname">Question 1</div>
<input type="text" value="" name="q1" />
</span>
The relevant jQuery:
$.each($('.a'), function(){
$thisField = $('.fieldname', $(this));
});
What exactly is being set to $thisField? If my understanding of multiple selectors in jQuery is correct, it should be grabbing the outer <span> element AND the inner <div> element. But for some reason, if I use $thisField.prepend("hi"); it ends up putting hi right before the text Question 1, but not before <div>. I thought multiple selectors would grab both elements, and that prepend() adds hi to the beginning of BOTH elements, not just the <div>