Multiple Element Selector is used to select multiple elements.
<html> <head> <title> My First Programme </title> </head> <body> <h1> JQuery </h1> <p class = "para1"> First Paragraph </p> <p class = "para2"> Second Paragraph </p> <p class = "para3"> Third Paragraph </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() { $('h1, p').text("All the contents of h1 element and p element got replaced") }); </script> </body> </html>
So, if you see the above code. We can see that there are three <p> elements,
<p class = "para1"> First Paragraph </p> <p class = "para2"> Second Paragraph </p> <p class = "para3"> Third Paragraph </p>
And one <h1> element.
And on button click, all the contents of <h1> as well as <p> element got changed to All the contents of h1 element and p element got replaced.
And this happened with multiple element selector.
$('button').click( function() { $('h1, p').text("All the contents of h1 element and p element got replaced") });
The moment the button is clicked, JQuery statement gets triggered.
$('h1, p').text("All the contents of h1 element and p element got replaced")
And the JQuery code locates the <h1> and <p> element and changes its contents.