Sookie J
Sookie J

Reputation: 893

In jQuery, what does "find('> span')" do?

I don't understand what find('> span') does.

Could you please explain it?

HTML Code

<button>Ibis<span class="bg"><span>Ibis</span></span></button>

jQuery Code

$(this).find('> span').animate( { width: '100%' } );

Upvotes: 2

Views: 792

Answers (1)

Ted
Ted

Reputation: 14927

$(this).find('> span')

finds a span that is an immediate child of this

In your example, it finds the <span class="bg">, but not the <span> within that <span class="bg">

Jquery selectors work much like CSS selectors. It is like writing button > span in CSS. That gives you the immediate child span only. Without the >, it would be like writing button span in CSS, which would effect all spans within the <button>

HTH :) and welcome to StackOverflow

Upvotes: 2

Related Questions