11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

adding content to the document. Because of this some proprietary features like Microsoft‘s<br />

innerHTML are being added to even strict standards-compliant browsers. Furthermore, other<br />

features live on simply because IE is by far the dominant browser. Because of the reality of IE‘s<br />

dominance, let‘s take another look at a few of the 4.x-generation Browser Object Models that<br />

refuse to die.<br />

<strong>The</strong> Power of innerHTML<br />

Netscape 6+, Opera 7+, and Internet Explorer 4+ all support the non-standard innerHTML<br />

property. This property allows easy reading and modification of the HTML content of an<br />

element. <strong>The</strong> innerHTML property holds a string representing the HTML contained by an<br />

element. Given this HTML markup,<br />

This is a test paragraph.<br />

the following script retrieves the enclosed content,<br />

var theElement = document.getElementById("para1");<br />

alert(theElement.innerHTML);<br />

as shown here:<br />

You can also set the contents of the HTML elements easily with the innerHTML property. <strong>The</strong><br />

following simple example provides a form field to modify the contents of a tag. Try<br />

running the example and adding in HTML markup. As you will see, it is far easier to add HTML<br />

content to nodes using this property than by creating and setting nodes using standard DOM<br />

methods.<br />

<br />

<br />

<br />

innerHTML Tester<br />

<br />

<br />

<br />

This is a test of innerHTML.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!