hide element jquery code example

Example 1: jquery display none

The correct way to do this is to use show and hide:

$('#id').hide();
$('#id').show();

An alternate way is to use the jQuery css method:

$("#id").css("display", "none");
$("#id").css("display", "block");

Example 2: hidden jquery

$('#yourid').attr('hidden', false);
$('#yourid').attr('hidden', true);

Example 3: jquery show hide

$("#hide").click(function(){
  $("p").hide();
});

$("#show").click(function(){
  $("p").show();
});

Example 4: jquery to hide a div

<div id="main"> 
  <p> Hide/show this div </p>
</div>

('#main').hide(); //to hide

// 2nd way, by injecting css using jquery
$("#main").css("display", "none");

Tags:

Html Example