Plexus81 Plexus81 - 2 days ago 4
jQuery Question

$(this +"selector") ? $("img",this) possible?

I'm trying to "select" a img inside a $(this) selector. I know I can find it by using

.find('img')
but is this possible:

$("img",this)
?

What's the most optimal way to do this?

Originally code

<a class="picture" href="test.html">
<img src="picture.jpg" alt="awesome">
</a>

Answer

What's the most optimal way to do this?

Both $(this).find('img') and $('img', this) are equivalent.

From the docs:

Internally, selector context is implemented with the .find() method, so $('span', this) is equivalent to $(this).find('span').

http://api.jquery.com/jQuery/

Comments