Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.innerHTML giving tag names in lower case

I am iterating NodeList to get Node data, but while using Node.innerHTML i am getting the tag names in lowercase.

Actual Tags

<Panel><Label>test</Label></Panel>

giving as

<panel><label>test</label></panel>

I need these tags as it is. Is it possible to get it with regular expression? I am using it with dojo (is there any way in dojo?).

var xhrArgs = {
            url: "./user/"+Runtime.userName+"/ws/workspace/"+Workbench.getProject()+"/lib/custom/"+(first.type).replace(".","/")+".html",
            content: {},
            sync:true,
            load: function(data){
                var test = domConstruct.toDom(data);
                dojo.forEach(dojo.query("[id]",test),function(node){
                    domAttr.remove(node,"id");
                });
                var childEle = "";
                dojo.forEach(test.childNodes,function(node){
                    if(node.innerHTML){
                            childEle+=node.innerHTML;
                    }
                });
                command.add(new ModifyCommand(newWidget,{},childEle,context));
            }
    };
like image 665
Dyapa Srikanth Avatar asked Oct 21 '22 12:10

Dyapa Srikanth


1 Answers

You cannot count on .innerHTML preserving the exact nature of your original HTML. In fact, in some browsers, it's significantly different (though generates the same results) with different quotation, case, order of attributes, etc...

It is much better to not rely on the preservation of case and adjust your javascript to deal with uncertain case.

It is certainly possible to use a regular expression to do a case insensitive search (the "i" flag designates its searches as case insensitive), though it is generally much, much better to use direct DOM access/searching rather than innerHTML searching. You'd have to tell us more about what exactly you're trying to do before we could offer some code.

like image 68
jfriend00 Avatar answered Nov 03 '22 00:11

jfriend00