I have this part many times in a page:
<a class="showComment" style="cursor: pointer;"><i class="icon-comment"></i> Views</a>
<br />
<br />
<div class="writeComment" style="height: auto; width: 700px;" dir="ltr" hidden="hidden">
</div>
I am now writing code in a js file for a.showComment
click event.Now I want to select next div.writeComment
.How to select it?
In the variable nextDiv you can do whatever you want
Using .nextAll()
method allows us to search through the successors of these elements in the DOM tree and construct a new jQuery object from the matching elements.
using .next()
instead you search after the DOM element that you have clicked
try this:
$('.showComment').click(function(){
var nextDiv = $(this).nextAll("div.writeComment");
});
Or
$('.showComment').click(function(){
var nextDiv = $('.showComment').next().find('.writeComment')
});
Or
$('.showComment').click(function(){
var nextDiv = $(this).next("div.writeComment");
});
next() didnt work.
nextAll() was for all of .writeComment elements that were after my .showComment element.But I found the issue.The following code made it.
$('.showComment').click(function(){
$(this).nextAll(".writeComment").first();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With