SFernando
SFernando

Reputation: 1124

prevent auto tag generate in javascript innerHTML

Why does

theMenuSection.innerHTML='<ul>';
alert(theMenuSection.innerHTML);

Produce <ul> </ul> just i have the opening tag.can i get <ul> from innerHTML tag

thanks

Upvotes: 0

Views: 111

Answers (1)

Steve
Steve

Reputation: 113

Typically (this is per-browser dependent) when you interact with the DOM, or utilize innerHTML (which interacts with the DOM), you will see the browsers "corrected" interpretation of what the HTML should look like. Same reason why Firefox auto-injects "thead" elements into tables when your source code doesn't have any of that. The browser is trying to infer 'correct' HTML from what it sees.

Upvotes: 1

Related Questions