Class Selectors Example in JQuery


The . class selector selects all elements with the specific class. The class refers to the class attribute of an HTML element. The class attribute is used to set a particular style for several HTML elements.

Source Code

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Class Selector Example</title>
    <!--------META-------->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <!------JQUERY CDN---->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  </head>
  <body>
    <h3>Class Selector Example</h3>
    <p>This para will be hide</p>
    <button type="button">Hide Para</button>
    
    <button type="button" class="showBtn">Show Para</button>
    <script>
      $(document).ready(function(){
      	$("button").click(function()
      	{
      	  $("p").hide();
      	});
      });
      
      $(document).ready(function()
      {
      	$(".showBtn").click(function()
      	{
      	  $("p").show();
      	});
      });
    </script>
  </body>
</html>
To download raw file Click Here

Learn All in Tamil © Designed & Developed By Tutor Joes