Reputation: 753
How can i select the first div with a specific class with jquery?
Ex : i want to put some html in the first p tag when i click on the first a.a_preview etc...
<a href="#" class="a_preview">Preview</a><br />
<div class="preview_div><p>Some text</p></div>
<a href="#" class="a_preview">Preview</a><br />
<div class="preview_div><p>Some text</p></div>
<a href="#" class="a_preview">Preview</a><br />
<div class="preview_div><p>Some text</p></div>
Upvotes: 1
Views: 3455
Reputation: 148524
$(".a_preview").click (function (e) {
$(this).nextUntil("a").find("p").html("aaaaa");
});
http://jsbin.com/imavug/edit#javascript,html
Upvotes: 4