Using Javascript to add HTML code to a web page


Extracting HTML code or text from an iframe from the parent document

var all_text = window.frames[' iframe_name'].document.body.innerHTML

Changing HTML code in a webpage

function enterHTML(passed)
var targt = passed; //value passed is the DIV id 'targetloc'
var initial = document.getElementById(targt) ;
initial.innerHTML = "<P>New Form <\/P> \n <FORM> <INPUT TYPE = 'button'" + " VALUE = 'Test Me'" +'onClick = "alert' + "('it works')"+ '"'+ "> <\/FORM>";
var textresult =initial.innerText;

Click to demonstrate the innerHTML function.

This text to be replaced by a form with a button.

Escaped Characters.

Syntax ___ Character Comment
\n new line Makes the resulting code more readable
\r carriage return
\' single quote
\" quotation marks
\/ back slash Used in closing an html element </p> would be <\/p>

Site Index