qadenza
qadenza

Reputation: 9293

next("some class") doesn't work

HTML

<div class="linksrtitle">Lorem ipsum</div>
<div class="linksrspace"></div>
<div class="linksrwrap">  // this div should be slided
<a class="linkr" href="volim-da-stoje.php">Lorem ipsum</a>
<a class="linkr" href="ova-salate-je-umrla.php">Lorem ipsum</a>
<a class="linkr" href="nova-rasa.php">Lorem ipsum</a>
</div>
<div class="linksrspace"></div>

JS

$(".linksrtitle").click(function(){
   $(this).next(".linksrwrap").slideToggle();  // doesn't work
});

Why this click event doesn't work. Console is empty.

Upvotes: 1

Views: 39

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115222

Use nextAll()(with first(), if multiple sibling with same class are there) to get that. next() only select immediate following sibling.

$(".linksrtitle").click(function() {
  $(this).nextAll(".linksrwrap").slideToggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="linksrtitle">Lorem ipsum</div>
<div class="linksrspace"></div>
<div class="linksrwrap">// this div should be slided
  <a class="linkr" href="volim-da-stoje.php">Lorem ipsum</a>
  <a class="linkr" href="ova-salate-je-umrla.php">Lorem ipsum</a>
  <a class="linkr" href="nova-rasa.php">Lorem ipsum</a>
</div>
<div class="linksrspace"></div>

Upvotes: 2

Related Questions