.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> JQuery >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

show hide control using JQuery code

Posted By:JQuery Developer       Posted Date: May 28, 2013    Points: 40    Category: JQuery    URL: http://www.dotnetspark.com  

Below code is used to show hide controls using JQuery code in our web form with an sample example.

When you need to show hide html element you can use below jQuery Code to show/hide in a very easy way using show() and hide() method.

Lets see an example with html div tag

I have created one html div tag in my web form

now we will use JQUery show() method to show the div tag

show element using JQuery


$('#myDiv').show(); // Show div element


hide element using JQuery

$('#myDiv').hide(); // Hide the div tag

Try live demo

Full html and JQuery code to show/hide div tag


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>My Page Title</title>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $('#myButton').click(function () {
                if ($(this).val() == "Hide") {
                    $('#myDiv').hide(); // Hide the div tag
                    $(this).attr("value", "Show");
                else {
                    $('#myDiv').show(); // show div element
                    $(this).attr("value", "Hide");

    <form id="form1" runat="server">
    <div id="myDiv" style="color: #0000FF; background-color: Lime; width: 150px">
        Hello Word!!!!
    <br />
    <input type="button" id="myButton" name="name" value="Hide" />



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend