What is replaceWith() method?

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

replaceWith(content) method literally replaces the original element along with it's contents .


<!DOCTYPE html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
$('#myspan').replaceWith('This is a <i>italic text</i>.This is another <i>italic text</i>.');
<button id="btn1">Exampleof replaceWith(Content)</button>
<span id="myspan">This is a <b>bold text</b>.This is another <b>bold text</b>.</span>


When we click on the "Exampleof replaceWith(Content)" button , the output becomes

This is a <i>italic text</i>.This is another <i>italic text</i>. 

This indicates that the original span tag along with it's contents has been replaced.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response