How to use jQuery to Search and Replace HTML elements? Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Using jQuery, you can dynamically search and replace HTML elements on a webpage. By selecting elements and binding actions to events, you can manipulate their content or structure in response to user interactions or other triggers ApproachIntegrate the jQuery library hosted on a content delivery network (CDN), ensuring access to jQuery functionalities.Two buttons with classes "one" and "two" are defined, each bound to a click event handler using jQuery.When the "Correct Me!" button is clicked, jQuery targets the <h1> element and replaces its text content with "Geeks for Geeks!".Upon clicking the "Add Me!" button, jQuery targets a <span> element and replaces its HTML content with an <h3> element containing the text "You can also Contribute.".Basic CSS styles are applied to <h1> elements to change their color to green and align the body content to the center.Example: The below example shows the above-explained approach. HTML <!DOCTYPE html> <html> <head> <title>jQuery!!!</title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"> </script> <style type="text/css"> h1 { color: green; } body { text-align: center; } </style> </head> <body> <h1>Geeks Geeks</h1> <br> <button class="one">Correct Me!</button> <br> <br> <button class="two">Add Me!</button> <br> <span></span> <script type="text/javascript"> $(".one").click(function () { $("h1").text("Geeks for Geeks!"); }); $(".two").click(function () { $("span").html("<h3>You can also Contribute.</h3>"); }); </script> </body> </html> Output: Output Comment More info J joshi08 Follow Improve Article Tags : Web Technologies JQuery HTML-Misc jQuery-Selectors jQuery-Questions +1 More Explore jQuery Tutorial 8 min read Getting Started with jQuery 4 min read jQuery Introduction 7 min read jQuery Syntax 2 min read jQuery CDN 4 min read jQuery SelectorsJQuery Selectors 5 min read jQuery * Selector 1 min read jQuery #id Selector 1 min read jQuery .class Selector 1 min read jQuery EventsjQuery Events 4 min read jQuery bind() Method 2 min read jQuery blur() Method 1 min read jQuery change() Method 2 min read jQuery EffectsjQuery animate() Method 2 min read jQuery clearQueue() Method 2 min read jQuery delay() Method 2 min read jQuery HTML/CSSjQuery addClass() Method 2 min read jQuery after() Method 1 min read jQuery append() Method 2 min read jQuery TraversingjQuery | Traversing 4 min read jQuery add() method 1 min read jQuery addBack() Method 2 min read Like