I have multiple expanding / collapsing boxes on a single page being generated by PHP / MySQL.
Problem is, when I click on one link to expand a box, it expands all the boxes.
I thought about appending the post ID at the end of the class (<div class="postreplycontainer-POST_ID">
) but I am not sure if that will work since I'd have to figure out a way to change the jQuery.
Here's a working example: http://jsfiddle.net/Draven/kUhkP/35/
Keep in mind, I can't manually code in each box because I am pulling the content from the database.
EDIT: Maybe somebody can help me with an additional problem.
I want to focus the textarea
box when I expand the <div>
. I tried using the same trick as before (using .closest
but that didn't work).
Here's the example: http://jsfiddle.net/Draven/kUhkP/53/
This example will always focus the first <textarea>
.
In jQuery , the show() and hide() method are used to show or hide any element in HTML. We can use these functions to collapse or expand the div tag as shown below. Copy $('.
Expand takes the current member / element and exposes the elements in the next level down of the hierarchy - effectively showing itself and its 'children'. Collapse takes a currently expanded member / element and undoes the expanded mode, hiding all the exposes levels of the hierarchy beneath it.
collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.
Here's the FIDDLE
$("a.postreply").click(function () {
$(this).closest('.blog-container')
.find('.postreplycontainer').slideToggle("fast");
});
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