shanthiram shanthiram - 9 days ago 5
jQuery Question

jquery show and hide on same link click

I have a div and I want to show and hide on a link click. Not two different links to show and hide but only one.
I have used toggle() but its not working for me..

Here is the code

<a id="showhidediv">show-hide</a>
<div id="maindiv">
<div id="innerleftdiv" style="width:49%;float:left">
</div>
<div id="innerrightdiv" style="width:49%;float:left">
</div>
<div>

<script text="text/javascript">
$().ready(function){
$("showhidediv").click(function(){
$("maindiv").hide()
});
</script>


Thanks

Answer

Thanks every one for trying to answer the question and every one was right..

I found the solution . The following is the jquery function

$("#showhide").click(function() { 
  if ( $("#maindiv").is(":visible") ) { 
    $("#maindiv").hide(); 
  } else if ( $("#maindiv").is(":hidden") ) { 
    $("#maindiv").show(); 
  }
});