zjrJS Javascript Library

zjrJS.Doc.aC() - zjrJS Javascript Library

This information lives on a webpage hosted at the following web address: 'https://omegajunior.globat.com/code/zjrjs/'.

How to use zjrJS.Doc.aC() ("append child")

Declaration
zjrJS.Doc.aC(HtmlElement Child, Optional HtmlElement Parent)

Goal
A wrapper around node.appendChild(), that checks for support, and appends the Child to the document (or body) if no Parent is specified.

Typical usage
When lots of elements need to be created, given all kinds of attributes and contents, and added to other elements. Writing D.aC(c,p) goes faster and results in smaller code than using p.appendChild(c), with the added benefit of a feature check.

Member Type
Function.

Value Type
Object (the Child HtmlElement, if appended successfully).

Parameters
HtmlElement Child: an element either generated (Doc.cE() or document.createElement()) or retrieved (Doc.eid() or document.getElementByID() etc.).
Optional HtmlElement Parent: the element to which the Child should be appended. This parameter is optional: if omitted or null, the Child will be appended to the document element (usually the body) instead.

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 HtmlParagraphElement
var P=D.cE("p");
if(P){
//add text to the paragraph
D.aC(D.cT("Hello, world!"),P);
//set some attributes to the paragraph
P.style.fontSize="x-large";
//add the paragraph to the body
D.aC(P);
}
//clean up memory
D=P=null;
});
/* ]]> */</script>
]

Download:

Download zjrJS’ latest stable build (20141202t2322) minified (7.1KB).

Download zjrJS’ latest stable build (20141202t2322) (11.9KB).

Clicky Analytics