var obj = element;
while (obj.nodeName != 'p' && obj.nodeName != 'body') {
obj = obj.parentNode;
}
if (obj.nodeName == 'p') {
document.body.insertBefore(p, obj);
}
This is the code in my javaScript function. I create a p element and I insert it before the last p element found. This code is working on xhtml files but not on html files. Can anyone tell me why?
Your browser is probably returning uppercase tag names when in HTML mode.
Use
nodeName.toLowerCase().