mardi 26 avril 2016

Why does this if scope in my function is completely ignored by javascript interpreter?

I have a function to practically create an HTML element and bind it quickly. However it does not work as it should be. When I use debug(ggCreateElement), I see that it skips if scope entirely even if the statement is "true". I ve ran out of ideas.

function ggCreateElement(tagName,className,idName,appendPointTagName) {
    d=document.createElement(tagName);
    d.className=className;
    d.id=idName;
    ap=document.getElementsByTagName(appendPointTagName);
        if (ap.lenght==0) {
           console.log("Append point tag name is not found ! ") ;
        }
        else {
           ap[0].appendChild(d);
           return d;
    }
}

Could you help me out please ? Thank you.

Aucun commentaire:

Enregistrer un commentaire