Skip to content Skip to sidebar Skip to footer

Expanding Div - Only Want The Clicked Div To Expand In Php Echo

I have results echo'ed from a database, i have included jquery expand code to expand the div when the title is clicked, however currently when a title of one result is clicked, all

Solution 1:

You can try using $(this) inside to only find elements relative to the current clicked

$(document).ready(function(){    
    $(".expanderHead").click(function(){
        var $exsign = $("#expanderSign");
        $(this).find("#expanderContent").slideToggle();
        $exsign.html($exsign.text() == '+' ? '-': '+');   
        // simplify your if/else into one line using ternary operator
        // if  $exsign.text() == "+" then use "-" else "+"
    });    
});

Solution 2:

probably because you are expanding the whole .class instead of the unique #id of the clicked div.

about your comment

okay thankyou for clearing this up, do you know how i could add a count function in to the div id name so that it would work?

see if this can help you:

dynamic id with php
http://perishablepress.com/dynamic-body-class-id-php-wordpress/

dynamic id with jquery
jQuery selection with dynamic id's


Post a Comment for "Expanding Div - Only Want The Clicked Div To Expand In Php Echo"