jQuery html() method example

In this post,  we are going to see jQuery html method.
html method is used to get html content of first matched elements,  other elements will be ignored and html('new html content') is used to set html content for all matched elements. 
Syntax for html() :
Example :
Syntax for html('new html content') :
$("selectors").html('new html content') 
 $("div").html('this text is being set by html method');
Let's understand with the help of example:
  <title>Jquery html method example </title>
  <script src="http://code.jquery.com/jquery-2.2.3.min.js"></script>
<h2>Jquery html method example</h2>
        border:4px dotted black;
<script type="text/javascript">
         alert($("div").html()) ;
         $("div").html('this text is being set by html() method');

  <button id="htmlButton">Using html</button>
  <button id="setHtmlButton">Using html('new html content') </button>
<button id="reset">Reset</button>
<br />
<div class='blackBorder'>
 Hello world from java2blog!!!!
<div class='blackBorder' >
 Welcome to JQuery.
Live demo:Jquery html method example on jsbin.com

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus


Java tutorial for beginners Copyright © 2012