InnerHTML JavaScript Functions

InnerHTML JavaScript Functions

By Shawn Olson

Posted on 01.14.05

When building custom JavaScript applications, it’s often beneficial to reference objects with named ids.

I have provided three new simple functions for manipulating and analyzing content inside a named HTML element.

To use these scripts you must reference objects by naming them with the id attribute… for example:

<div id= “customBox”>This is my custom Div Container.</div>
(See Using an Object Id with JavaScript for more info.)

Function insideHTML(cell):


This function will return all content inside an HTML element… Applied to the example div tag above, it would return “This is my custom Div Container”. It is the equivalent of returning document.getElementId(“customBox”).innerHTML .

Function checkValueAgainst(objId,val1):


This function evaluates the content of an HTML object designated by “objId” using insideHTML() and compares it to the value passed in “val1”. If the values are identical, this function returns TRUE. If the values are not identical, the function returns false;

Function makeRemark(target,statement):


This function will fill a named HTML element (designated in “target”) with the value passed to “statement”. For example, to change the content of “customBox” above to “Hello World”, we would run type makeRemark(‘customBox’,‘Hello World’).

Example of Functions In Use


Cell 1Cell 2Cell 3Custom
RTR


Remark

Enter A Remark Below



To use these functions, you must add the following line into the head of your HTML:

<script type="text/javascript" src="http://www.shawnolson.net/scripts/public_smo_scripts2.js">
</script>


If you copy these functions into your own scripts, please provide credit to this sitePlease include credit when using this script and read this site's Terms & Conditions before using.
Copyright © 2005-2008 by Shawn Olson.
Shawn Olson Creative Arts
sitemap RGB Color Columbus Photography Free Word Search Maker monty hall game Hangman John Dewey