|
-
November 7th, 2011, 11:13 AM
#3
Re: jquery - show multiple divs
If you want to access a specific element in jQuery, then use the #selector, as you've done, but if you want to access a group of elements, I would suggest assigning a class to them and then use the .selector to get to all the elements of that class.
So in the code below I have assigned a click function to the specific importantImg ID, but then iterate through each class member and change its display. I've used toggle but just change it to show if you only want one way display.
<style>
.showhide {
display:none;
}
</style>
<script type="text/javascript">
$(function(){
$('#importantImg').bind('click',function(event) {
$('.showhide').each( function() { $(this).toggle(); });
});
});
</script>
</head>
<body>
<div id="importantImg"><a href="#">Click here</a></div>
<div id="divLayer3" class="showhide" >divLayer3<br/></div>
<div id="divLayer4" class="showhide" >divLayer4<br/></div>
<div id="divLayer5" class="showhide" >divLayer5<br/></div>
</body>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|