For example given this HTML:
<div>
<p>p0</p>
<p>p1</p>
<p>p2</p>
</div>
I don’t understand how to write a concatenated jQuery this selector, that is something like this:
$("div").on("mouseover", function () {
$(this + " p").css({
color: "#009"
});
});
What is the correct syntax for this?
To find elements within another, use a contextual selector. Try this:
Or you can concatenate the
idof the parent – although this is a little ugly IMO:Or you can use
find()on the parent element:Any of the above will work for you, although the second example is pretty ugly and should be avoided. Always use the
thisreference directly where possible.