Jump to content

javascript toggle divs problem


esoteric

Recommended Posts

Im trying to write a script so that upon clicking a link (which is a image in this case) it toggles a div displaying the necessary info below.

 

the javascript

<script type="text/javascript">
$(document).ready(function(){
    $(".slidingDiv1").hide();
$(".show_hide1").show();

$('.show_hide1').click(function(){
$(".slidingDiv1").slideToggle();
});
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $(".slidingDiv2").hide();
$(".show_hide2").show();

$('.show_hide2').click(function(){
$(".slidingDiv2").slideToggle();
});
});
</script>

 

snip from table

<tr>
          <td class="style1"> News </td>
          <td><a href="#" class="show_hide1"><img src="/img/add-icon.gif" width="16" height="16" alt="" /></a></td>
          <td><a href="#" class="show_hide2"><img src="img/hr.gif" width="16" height="16" alt="" /></a></td>
          <td><img src="img/edit-icon.gif" width="16" height="16" alt="" /></td>
          <td><img src="img/login-icon.gif" width="16" height="16" alt="" /></td>
          <td><img src="img/save-icon.gif" width="16" height="16" alt="save" /></td>
          <td><img src="img/add-icon.gif" width="16" height="16" alt="add" /></td>
</tr>

 

the content that will be displayed upon pressing the link

<div class="slidingDiv1"> 
<div id="admin_form">
  		<a href="#" class="show_hide1">Hide Form</a>
        form 1 test content
	</div>
</div>

 

Is it possible to hide all other divs when clicking a new link so only the relevant info is being shown?

 

Also is there a way to cut this code down a bit rather than creating x amount of function that all do the exact same thing but just show different divs? Im going to have at least 20 in total so it seems a lot of wasted code if there is a way to cut it down.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.