prestarocket
prestarocket

Reputation: 753

jquery selector : select first div with a specific class after some element

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

Answers (1)

Royi Namir
Royi Namir

Reputation: 148524

$(".a_preview").click (function (e) {

$(this).nextUntil("a").find("p").html("aaaaa");
});

http://jsbin.com/imavug/edit#javascript,html

Upvotes: 4

Related Questions