getElementsByTagName('head') returns one head even if more are defined in the page

I know that a web page has an implied <head> tag even when there is none declared in the file. I was just curious in testing getElementsByTagName('head') when there is none and it does return a <head> tag.

However, when I placed more than one <head> in the page... it returns a unified head. why is this?

Answers


That's because the browser "corrects" your HTML to always include a single <head>. Otherwise your HTML is invalid.


HTML parsers are said to be very much forgiving(I heard this feature makes them faster, not sure) about errors in parsing and evaluating HTML. Whatever you give, it will parse it without any error trying to be near to what you meant. So you are only supposed to have one head element. The browser will change it to a correct form, depending on the implementation. So when the javascript executes it will return the existing head element, after the correction.


Need Your Help

Transmitting data with CoreBluetooth

ios bluetooth core-bluetooth bluetooth-lowenergy

I'm developing an iOS app with an accompanying Bluetooth LE peripheral. The one step I don't seem to be able to solve is how to actually transmit the data from my app to the peripheral or vice ver...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.