• New Scripts
  • Popular Scripts
  • Top Scripts
  • Rss feed

Php Scripts

  • PHP Scripts
  • How to Add Link
  • Sponsor Listing
  • Login
  • Register
  • Getting Rated
  • Blog
  • Home
  • Subscribe to Feed
Blog > Tutorials > jQuery > jQuery to show/hide divs using radio button

jQuery to show/hide divs using radio button

Posted on May 5, 2011, 12:34 pm, by Scripts, under jQuery.

Use the jQuery to show/hide the divs using the radio button

Start with Radio button

Add two radio button with name myRadio  value should be the different like
1. myDiv_1
2. myDiv_2

You can also use the

Show to Radio 1
Hide to Radio2

<input id="Div_1" name="myRadio" type="radio" value="myDiv_1" /> Radio 1
<input id="Div_2" name="myRadio" type="radio" value="myDiv_2" /> Radio 2

Now design the two new div to execute the command
First div id is myDiv_1 and you can also add the some style to define the div style, add the second div with id myDiv_2 with some style. 

<div id="myDiv_1" style="width: 500px; background: white; color: black; border: 1px solid; padding: 5px;">

Content of Div 1
...
..
.

</div>

<div id="myDiv_2" style="width: 790px; background: white; color: black; border: 1px solid; padding: 5px;">
Content of Div 2
...
..
.</div>

Now you need to add the jQuery code to run the function properly 

<script LANGUAGE="JavaScript">

  $(document).ready(function(){ 
    $("input[name$='myRadio']").click(function() {
        var try = $(this).val();
        $("div.MyDiv").hide();
        $("#"+try).show();

} 

 });  
    
</script>

It’s very easy to do this with jQuery, try it now and add your comments.

Tags: jquery, radio button, show/hide
Comment (RSS)  |  Trackback

Leave a Reply

Click here to cancel reply.

Spam Protection by WP-SpamFree

« PHP Image Gallery

Categories

  • Announcements
  • Best Scripts
  • Tutorials
  • JavaScripts
  • PHP Scripts

Tags

htaccess image gallery include jquery mod_rewrite photo gallery PHP PHP Scripts radio button SEO SEO Friendly URLs show/hide str_replace() Tutorials

Web Hosting



Home | Feedback | Privacy | Advertise with us
(c) Copyright 2006 AdvanceScripts™. All rights reserved.
No part of this website may be reproduced, copied and/or distributed in any medium without express written permission
Trademarks are property of their respective owners
Site Developed and Hosted by Ethic Solutions