How to use zjrJS.Doc.cE() ("create element")
Used zjrJS Version:
Stable Minified version 20141202t2322 of zjrJS.
Declaration
Goal
A cross-browser method to create new elements, to add to your document.
Typical usage
Wherever new elements need to be created and manipulated, and you don't feel like using DOM1 because it's too much writing, or for some reason you can't use DOM1.
Member Type
Function.
Value Type
Object (the created HtmlElement with the desired tag name), if such an element could be created.
Parameters
String tagName: any lowercase tag name, usually an Html tag like "p", "a", or "div". You can provide whatever tag name you wish, including the HTML5 ones and even your own made-up ones for use in XML.
Dependencies
None.
Example
Example copied out of zjrJS itself
Just to show that we eat our own dogfood:
zjrJS.Doc.cE(String tagName)
Goal
A cross-browser method to create new elements, to add to your document.
Typical usage
Wherever new elements need to be created and manipulated, and you don't feel like using DOM1 because it's too much writing, or for some reason you can't use DOM1.
Member Type
Function.
Value Type
Object (the created HtmlElement with the desired tag name), if such an element could be created.
Parameters
String tagName: any lowercase tag name, usually an Html tag like "p", "a", or "div". You can provide whatever tag name you wish, including the HTML5 ones and even your own made-up ones for use in XML.
Dependencies
None.
Example
<script type="text/javascript" src="zjrJS.version.js" id="zjrJS"></script>
<script type="text/javascript">/* <![CDATA[ */
zjrJS.Doc.aE(window, "load", function(){
//reference the Doc object
var D=zjrJS.Doc;
//create an HtmlAnchorElement (hyperlink)
var A=D.cE("a");
if(A){
//add text to the paragraph
D.aC(D.cT("Follow me"), A);
A.href="https://www.omegajunior.net/";
A.title="Visit the OmegaJunior Consultancy!";
A.style.textDecoration="underline";
//add the paragraph to the body
D.aC(A);
}
//clean up memory
D=A=null;
});
/* ]]> */</script>
Example copied out of zjrJS itself
Just to show that we eat our own dogfood:
h5A: function(){
/* apparently MSIE 5 through 8 react better to HTML5 objects after creating them through JS */
var r, es=[ 'article', 'aside', 'audio', 'canvas', 'details', 'embed', 'figure', 'footer', 'header', 'nav', 'section', 'source', 'time' ];
for(var i = es.length: i>-1; i--){
r = zjrJS.Doc.cE(es[ i ])
}
es=r=null;
}