Why do we use replaceAll() method in jQuery?

 Posted by Rajnilari2015 on 12/19/2015 | Category: jQuery Interview questions | Views: 1736 | Points: 40
Answer:

replaceAll() method replaces all the selected elements with new HTML elements

e.g. te below code replace all the bold (b) elements with i(italic) elements with the text inside the b tag

<!DOCTYPE html>

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("<i>italic text</i>").replaceAll("b");
});
});
</script>
</head>
<body>

<button>Replace all b(bold) elements with i(italic) elements</button><br>

<p>This is a <b>bold text</b>.This is another <b>bold text</b>.</p>
</body>
</html>


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response