javascripthtmljqueryjquery-selectorsuislider

How can I select the next div using jQuery?


I am quite a noob when it comes to jQuery and I'm trying to select the next element using the next() selector but having a little trouble in getting it to work!

What I'm trying to do is to activate slideDown() once the user has finished making their selection on a ui slider. Here is my code:

$('.slider').slider({
   stop: function(event, ui) {
       $(this).nextAll('.secondq:first').slideDown('slow') 
   }
});

Trouble is, this doesn't work at all. It will only work if I put the 'secondq' question inside the parent div of the ui slider. Here is my HTML:

<div class="option">
                            <h2 align="left">How high is your ceiling from the floor?</h2>
                            <input type="text" align="right" name="bonus" class="value" disabled="disabled"  />
                            <div class="slidewrap">
                                <div class="sliderFt slider"></div>
                            </div>
                        </div>
                        <!-- End Option -->
                        <div class="option">
                            <h2 align="left">How many windows do you have?</h2>
                            <input type="text" align="right" name="bonus" class="value" disabled="disabled"  />
                            <div class="slidewrap">
                                <div class="sliderWinDoor slider"></div>
                            </div>
                            <div class="secondq" style="display:none;">
                                <h2>What type of material are your windows made of?</h2>
                                <div class="radiocont">
                                    <label>Wood</label>
                                    <input type="radio" class="styled" value="wood" name="windowtype" />
                                </div>
                                <div class="radiocont">
                                    <label>Metal</label>
                                    <input type="radio" class="styled" value="metal" name="windowtype" />
                                </div>
                                <div class="radiocont">
                                    <label>PVC</label>
                                    <input type="radio" class="styled" value="pvc" name="windowtype" />
                                </div>
                            </div>
                        </div>

Solution

  • nextAll only gets siblings. Based on your HTML structure, you could do:

    $(this).parent().next()
    

    To make it more independent from the structure, you could also do:

    $(this).closest('.slidewrap').nextAll('.secondq:first')