When I click a node in a drupal view it toggles the body for every node in my view instead of just the node I am clicking. How can I get jquery to toggle just the node I am clicking? Here is my code in the head of my node template (node-type.tpl.php)
<script>
$("button").click(function () {
$(".more").toggle();
});
</script>
And the code for the body to be toggled.
<div class="more"><?php print $node->content['body']['#value']; ?></div>
Currently it toggles every div with the class “more” in my entire view instead of just in the node which I am clicking. How do I restrict it to just the clicked node?
I would also like it if only body were open at a time. ie; when a different node is clicked, the previous node’s body toggles closed.
I’m sure it’s probably easy but I just can’t seem to figure it out…
Where is the button relative to
.more?If the button is in the
.moreelement, you want to do something like this:If the button is not a parent or ancestor of
.more, you will need to do a little more. If the buttons are in the same order as the.moreelements (and there aren’t any unrelated buttons), you can do this:However, you are better off linking the button to the
.morecontent with anidand ahref, or some jQuery data:Script:
Demo: http://jsfiddle.net/jtbowden/EfUxt/
There are libraries that help with these kinds of situations, such as jQuery UI Tabs.