I am having multiple jQuery sliding panel in the same page, however when i show or hide one panel, the others become shown or hidden as well.
anyone can solve this problem?
Thanks.
code:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".flip").click(function(){
$(".panel").slideToggle("slow");
});
});
</script>
<h3>Category: Health</h3>
<div class="panel" >
#{ifnot Posts}
No posts to view
#{/ifnot}
<ul>
#{list items:Posts, as: 'Post'}
<li>
<p>${Post.poster}</p><p>${Post.content}</p>
</li>
#{/list}
</ul>
<a id="addpost" href="#">add new Health's post</a>
</div>
<p value="health" class="flip">Show/Hide Posts</p>
<h3>Category: Politics</h3>
<div class="panel">
#{ifnot Posts}
No posts to view
#{/ifnot}
<ul>
#{list items:Posts, as: 'Post'}
<li>
<p>${Post.poster}:</p><p>${Post.content}</p>
</li>
#{/list}
</ul>
<p>
<a id="addpost" href="#">add new Politic's post</a>
</p>
</div>
<p id="health" class="flip">Show/Hide Posts</p>
<h3>Category: Entertainment</h3>
<div class="panel">
#{ifnot Posts}
No posts to view
#{/ifnot}
<ul>
#{list items:Posts, as: 'Post'}
<li>
<p>${Post.poster}</p><p>${Post.content}</p>
</li>
#{/list}
</ul>
<p>
<a id="addpost" href="#">add new Entertainment's post</a>
</p>
</div>
<p id="entertainment" class="flip">Show/Hide Posts</p>
Selectors apply a function to all elements that match it. For example a selector like
will match all elements that have the panel class.
A simple solution would be to use ids to identify the panel you want to operate on.
And then in the jquery selector address this panel explicitly using