menu

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.

Example:

<html>
 <head>
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  <script>
    $(document).ready(function() {
      $('#myButton').click(function () { 
  $('#myDiv').html('test');
      alert("Jquery object value " + $('#myDiv').html());
      alert("HTML Dom object value " + $('#myDiv')[0].innerHTML);
       return true;
      });   
     });
  </script>
 </head>
 <body>
   <input type="button" id="myButton" value="fill the div">
   <br/>
   <div id="myDiv"></div>
  </body>
</html>     

The screen will look like the following.


Using html() and innerHTML in JQuery
Figure 1

You can download the source code from here.

2 comments:

  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

    ReplyDelete
  2. At the same time, our experienced engineers guarantee the very best standards with leading edge software program and tools. You likely won’t be surprised to study that machines function extra shortly than folks do. You could obtain the final items in as little as 5 days whenever you Crotchless Panties purchase your CNC machined parts from a perfect CNC machine. It is made up of place and motion transducers that constantly monitor the placement and movement of the cutting device.

    ReplyDelete