Answer: html(content) method replaces the contents of the element
e.g.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#btn1').click(function(){
$('#myspan').html('This is a <i>italic text</i>.This is another <i>italic text</i>.');
});
});
</script>
</head>
<body>
<button id="btn1">Exampleof html(Content)</button>
<span id="myspan">This is a <b>bold text</b>.This is another <b>bold text</b>.</span>
</body>
</html>
When we click on the "Exampleof html(Content)" button , the output becomes
<span id="myspan">This is a <i>italic text</i>.This is another <i>italic text</i>.</span>
This indicates that the inner html content of the span tag has been replaced .
Asked In: Many Interviews |
Alert Moderator