- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery replaceAll() with Examples
The replaceAll() method in jQuery is used to replace selected elements with new HTML elements.
Syntax
The syntax is as follows −
$(content).replaceAll(selector)
Above, the content parameter is the content to insert, whereas the selector specifies which elements to be replaced.
Example
Let us now see an example to implement the jQuery replaceAll() method −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("<h2>New Heading</h2>").replaceAll("h2"); }); }); </script> </head> <style> div { margin: 10px; width: 60%; border: 2px dashed orange; padding: 5px; text-align:justify; } </style> <body> <div> <h2>Demo Heading 1</h2> <h2>Demo Heading 2</h2> <h2>Demo Heading 3</h2> <h2>Demo Heading 4</h2> </div> <p>Click the below button to update headings</p> <button>Click</button> </body> </html>
Output
This will produce the following output −
Click the button to update headings −
- Related Articles
- Matcher replaceAll() method in Java with Examples
- jQuery mousedown() with Examples
- jQuery mouseup() with Examples
- jQuery submit() with Examples
- jQuery resize() with Examples
- jQuery has() with Examples
- jQuery hasClass() with Examples
- jQuery mouseenter() with Examples
- jQuery mouseleave() with Examples
- jQuery mousemove() with Examples
- jQuery keypress() with Examples
- jQuery keyup() with Examples
- jQuery last() with Examples
- jQuery height() with Examples
- jQuery mouseout() with Examples

Advertisements