ドキュメント

Manipulation/replaceAll

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Manipulation

replaceAll( selector )

Replaces the elements matched by the specified selector with the matched elements. As of jQuery 1.3.2, returns all of the inserted elements.
This function is the complement to replaceWith() which does the same task with the parameters reversed.
Arguments:
selectorSelector
The elements to find and replace the matched elements with.
Examples:

Replace all the paragraphs with bold words.

$("<b>Paragraph. </b>").replaceAll("p"); // check replaceWith() examples

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("<b>Paragraph. </b>").replaceAll("p"); // check replaceWith() examples
  });
  </script>
  
</head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>

NameType