Home >Web Front-end >Front-end Q&A >What is the use of jquery replaceall method
jquery replaceAll() method is used to replace the selected elements with new HTML elements, the syntax is "$(content).replaceAll(selector)"; the parameter "selector" specifies the selected element, and "content" specifies Contains replacement content for HTML tags.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery replaceall() method
replaceAll() method replaces the selected elements with new HTML elements. Syntax format:
$(content).replaceAll(selector)
Description | |
---|---|
content | Required. Specifies the content to be inserted (must contain HTML tags).|
selector | Required. Specifies which element will be replaced.
$(A).replaceAll(B), which means replacing the B element with the A element.
Example 1: Replace the strong element with an a element
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(function() { $("button").click(function() { $('<a href="//m.sbmmt.com/" target="_blank">PHP中文网</a>').replaceAll("strong"); }) }) </script> </head> <body> <strong>jQuery教程</strong><br/> <br><button>隐藏textarea</button> </body> </html>
Example 2: Replace the last p element Description for the span element
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(function() { $("button").click(function() { $("<span><b>Hello world!</b></span>").replaceAll("p:last"); }) }) </script> </head> <body> <p>这是一个段落。</p> <p>这是另一个段落。</p> <br><br><button>隐藏textarea</button> </body> </html>: The
:last selector selects the last element. This selector only uses For selecting a single element
jQuery video tutorial, web front-end video]
The above is the detailed content of What is the use of jquery replaceall method. For more information, please follow other related articles on the PHP Chinese website!