Tom Rider
Tom Rider

Reputation: 2815

find element by attribute jquery

I have a div and i insert a data-test attribute in it :

<div id="container">
    <div data-test="test"></div>
</div>

Now i want to find inner div , with this expression :

alert($("#container").find("[data-test=test]").length);

But this is not working . Whats the problem here?

Upvotes: 0

Views: 116

Answers (1)

BlackSpy
BlackSpy

Reputation: 5603

try quoting your value:

alert($("#container").find('[data-test="test"]').length);

Upvotes: 1

Related Questions