OTARIKI OTARIKI - 1 year ago 81
Javascript Question

jquery this concat selector

For example given this html


I dont understood how to write jquery
this concat selector
, that is something like this

$("div").on("mouseover", function () {
$(this+" p").css({
color: "#009"


please tell, what is right syntax for this?

Answer Source

To find elements within another, use a contextual selector. Try this:

$("p", this).css({ /* ... */ });

Or you can concatenate the id of the parent - although this is a little ugly IMO:

$("#" + this.id + " p").css({ /* ... */ });

Or you can use find() on the parent element:

$(this).find("p").css({ /* ... */ });

Any of the above will work for you, although the second example is pretty ugly and should be avoided. Always use the this reference directly where possible.