html - The DOM tree is showing the title tag inside the BODY section and not in the HEAD section in the LIVE DOM viewer? Why is this happening? -
in order check working of dom tree (actually check how works if don't put tags orderly or write random text without using tag) touched upon live dom viewer.
as write title before text, dom tree shows in head section right way:
input:
<!doctype html> <title>xyz</title> random text output(what dom viewer shows):
doctype: html html head title #text: xyz #text: body #text: random text but when write text before title tag, shows title in body section , not in head. why happening? :
input:
<!doctype html> random text <title>xyz</title> output:
doctype: html html head body #text: random text title #text: xyz #text:
basically, when parser sees text directly inside head, insertion mode switched "in body", text appears inside body elements. following title elements won't moved head, because has been parsed.
specifically, code ...
<!doctype html> <title>xyz</title> random text ... parsed follows:
- the insertion mode set "initial"
- the parser sees doctype token. insertion mode switched "before html".
- the parser sees line break, ignored.
- the parser
<title>start tag.htmlelement created. insertion mode switched "before head", , token reprocessed. - the parser
<title>start tag.headstart tag inserted. insertion mode switched "in head", , token reprocessed. - the parser
<title>start tag. generic rcdata element parsing algorithm followed. - a
titleelement inserted. insertion mode switched "text". - the parser sees text. characters inserted.
- the parser sees
</title>end tag.titleelement popped off stack of open elements. insertion mode switched original one. - the parser sees text.
headelement popped off stack of open elements. insertion mode switched "after head", , token reprocessed. - the parser sees text.
bodystart tag inserted. insertion mode switched "in body", , token reprocessed. - the parser sees text. characters inserted.
- the parser sees end-of-file token. the end
and code ...
<!doctype html> random text <title>xyz</title> ... parsed follows:
- the insertion mode set "initial"
- the parser sees doctype token. insertion mode switched "before html".
- the parser sees line break, ignored.
- the parser sees text.
htmlelement created. insertion mode switched "before head", , token reprocessed. - the parser sees text.
headstart tag inserted. insertion mode switched "in head", , token reprocessed. - the parser sees text.
headelement popped off stack of open elements. insertion mode switched "after head", , token reprocessed. - the parser sees text.
bodystart tag inserted. insertion mode switched "in body", , token reprocessed. - the parser sees text. characters inserted.
- the parser sees
<title>start tag. token processed using "in head" insertion mode. - the parser sees
<title>start tag. generic rcdata element parsing algorithm followed. - a
titleelement inserted. insertion mode switched "text". - the parser sees text. characters inserted.
- the parser sees
</title>end tag.titleelement popped off stack of open elements. insertion mode switched original one. - the parser sees end-of-file token. the end
Comments
Post a Comment