InnerHTML JavaScript Functions

Posted Jan 13, 2005
Last Updated Nov 8, 2011

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 1 Cell 2 Cell 3 Custom
R T R

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.


2011-11-08 Once you get used to JavaScript, you'll find that JavaScript has very simple ways to do what these functions do. Furthermore, if you are using a framework like Prototype or jQuery, you'll find native features like these.

Comment

No HTML Tags are permitted.

latesh sarode

May 24, 2010

very good ,self explainatory...
Angry Teapot Level Design Awards

Newsletter Subscription