Friday, November 21, 2014

Using html() and innerHTML in JQuery

html() vs innerHTML:

     You can either use html() function to set or get value of a div using JQuery objects like $("#myDiv").html() or use innerHTML property of the html dom object like 
$("#myDiv")[0].innerHTML. You see that a JQuery object is hold an array of html dom objects of the same name. Below is an example of using these syntax.


  <script src=""></script>
    $(document).ready(function() {
      $('#myButton').click(function () { 
      alert("Jquery object value " + $('#myDiv').html());
      alert("HTML Dom object value " + $('#myDiv')[0].innerHTML);
       return true;
   <input type="button" id="myButton" value="fill the div">
   <div id="myDiv"></div>

The screen will look like the following.

Using html() and innerHTML in JQuery
Figure 1

You can download the source code from here.

1 comment:

  1. Beginners Guide to Baccarat | - Urlione
    Baccarat is a simple game of luck with a twist. The objective 1xbet korean is to 인카지노 find the best bet that you can win in a casino. With so many twists 바카라 사이트 to