How to Use jQuery hide() function for hiding the current HTML element


<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
  $(this).hide()
});
});
</script>
</head>

<body>
<button type="button">Click me</button>
</body>

</html>

Explanation:
The jQuery syntax is tailor made for selecting HTML elements and perform some action on the element(s).
Basic syntax is: $(selector).action()



  • A dollar sign to define jQuery
  • A (selector) to "query (or find)" HTML elements
  • An jQuery action() to be performed upon the element(s)
Examples:
$(this).hide() - hides current element
$("p").hide() - hides all paragraphs
$("p.test").hide() - hides all paragraphs with class="test"
$("#test").hide() - hides the element with id="test"