jQuery html method
jQuery html method : is used to get the html of the given element.
Syntax of jQuery html() method
Get Html
$(selector).html();
Note : It does not accepts any argument.
jQuery html Method Example 1
jQuery html() Method – Example 1 – Get The Html
<script type="text/javascript"> $(document).ready(function(){ $( "#htmlExample" ).on( "click", function(event) { var data = $("div").html(); alert(data); }); }); </script> |
Set Html
$(selector).html(html-data);
html-data: string containing the html.
jQuery html() method Example 2
jQuery html Method – Example 2 – Set The Html/h3>
<script type="text/javascript"> $(document).ready(function(){ $( "#htmlExample" ).on( "click", function(event) { $("div").html("<h3>I have been added using html() method...</h3>"); }); }); </script> |
Advertisements