Why do we use replaceAll() method in jQuery? [Resolved]

Posted by Kumarkrishna184 under jQuery on 12/19/2015 | Points: 10 | Views : 440 | Status : [Member] | Replies : 3
Why do we use replaceAll() method in jQuery?

Thanks and Regards,
Krishna Kumar



Responses

Posted by: Rajnilari2015 on: 12/19/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Suppose have the below HTML

<!DOCTYPE html>
<html>
<head>
</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>


Our objective is to replace all the bold (b) elements with i(italic) elements with the text inside the b tag .

We can do this by using replaceAll() method which replaces all the selected elements with new HTML elements as shown under

<!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>


Hope this helps

--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 12/19/2015 [Member] Starter | Points: 25

Up
0
Down
Thanks Sir.......

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/19/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Kumarkrishna184 Sir, glad that it helped you

--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response