Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




SELECTORS - * Selector


The '*' Selector is used to select all the HTML elements.


Example :



 <html>
    <head>
    	<title> My First Programme </title>
  	</head>

  	<body>
    	<h1> JQuery </h1>
    	<p> New Code </p>

    	<button> Click me </button>

      	<script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script>

      	<script>

			$('button').click( function() {
            	$('*').text("The entire HTML page got replaced")
            });

      	</script>
   </body>
</html>



Output :



So, in the above code what happens is, if we click on the button, the contents of the entire HTML page gets changed to The entire HTML page got replaced.


And the magic happens within the two lines of code of JQuery.


$('button').click( function() {
	$('*').text("The entire HTML page got replaced")
});

So, we are using the '*' selector to replace the contents of the HTML page.


And if we want to perform some action on button, JQuery provides a method called click().That actually says, do something if a button is clicked.


$('button').click();

And when the button is clicked, the line with '*' selector gets executed,


$('*').text("The entire HTML page got replaced")

Replacing the contents of the HTML page.