Doubt. Can I use next()?


#1


Hi, I started to do this project using .next() to try to simplify the code. I did it this way just to check if at least the dropdown menus were displayed when clicking on the <li>.Nevertheless it isn't working.


var main = function () {
  $('.dropdown').click(function() {
     $(this).next('.dropdown-menu').toggle();
  });
};

$(document).ready(main);


I have managed to come up with the right code, but I still have a doubt. Why with this code the dropdown menus don't display when clicking the listed items??

Thanks


#2

Hey there, next() method gets the immediately following sibling (link to jQuery docs). If you take a closer look at HTML code, your question will be answered. Hope that helps :slight_smile:

<li class="help dropdown">
  <h3>Help &#x25BE;</h3>
  <ul class="dropdown-menu">
    <li>FAQs</li>
    <li>Return Policy</li>
    <li>Shipping Info</li>

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.