{"id":98,"date":"2008-12-14T22:02:32","date_gmt":"2008-12-14T19:02:32","guid":{"rendered":"http:\/\/www.held.org.il\/blog\/?p=98"},"modified":"2012-05-21T02:31:07","modified_gmt":"2012-05-20T23:31:07","slug":"html-name-attribute-firefox-misbehaves","status":"publish","type":"post","link":"http:\/\/www.held.org.il\/blog\/2008\/12\/html-name-attribute-firefox-misbehaves\/","title":{"rendered":"HTML &quot;name&quot; attribute, Firefox misbehaves"},"content":{"rendered":"<p>It's been a long time since I wrote something about web-dev, that's because I code less web-stuff recently \ud83d\ude42<\/p>\n<h3>\"id\" vs. \"name\" attributes<\/h3>\n<p>so far, I thought that \"id\" should be used for unique IDs, and \"name\" can be used for non-unique names, i.e. multiple HTML tags with the same name. I've been using <em>document.getElement<strong>s<\/strong>ByName(str)<\/em> to get an array of elements with the same name.<\/p>\n<p>Today I've figured out that it's only partially legal: the <strong>name<\/strong> attribute can be used only for <strong>specific elements<\/strong> (such as INPUT), but cannot be used on many elements (such as DIV). For some reason, Firefox accepts the name tag for any HTML element, while IE follows HTML 4.01 and doesn't accept name tags for \"illegal\" HTML tags.<\/p>\n<h3>Proof of concept<\/h3>\n<p>The next piece of JS\/HTML code, gives different results on both browsers:<br \/>\n<code><br \/>\n&lt;div name=\"foo\"&gt;bla&lt;\/div&gt;<br \/>\n<span style=\"color: #808080;\">&lt;script type=\"text\/javascript\"&gt;<\/span><br \/>\n<strong> <\/strong>alert(document.getElementsByName(\"foo\").length)<br \/>\n<span style=\"color: #808080;\">&lt;\/script&gt;<\/span><br \/>\n<\/code><\/p>\n<p>Results:<\/p>\n<ul>\n<li><strong>Firefox 3: <\/strong>1<\/li>\n<li><strong>IE 7:<\/strong> 0<\/li>\n<\/ul>\n<p>Here is a <a href=\"http:\/\/jszen.blogspot.com\/2004\/07\/whats-in-name.html\">nice explanation<\/a> with a full list of \"name\"-allowed HTML tags.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been a long time since I wrote something about web-dev, that&#8217;s because I code less web-stuff recently \ud83d\ude42 &#8220;id&#8221; vs. &#8220;name&#8221; attributes so far, I thought that &#8220;id&#8221; should be used for unique IDs, and &#8220;name&#8221; can be used for non-unique names, i.e. multiple HTML tags with the same name. I&#8217;ve been using document.getElementsByName(str) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[196,55,66,202],"_links":{"self":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/98"}],"collection":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}