Reputation: 8541
I did some code with jquery that take the name attribute !!! OF A DIV !!! and use it in some way.
if in one hand i tryed this code in every browser i have (firefox, chrome, ie 9/8/7, safari, opera, android... all with last update) and it work perfectly, in the other hand i see that - searching with google - "name" is considered only into form, input, textarea, a and other similar.
can i really use it in the way i did? in every html tag I want? or I'll burn forever in the hell?
thank you in advance
seen your answers, I decided to store datas in other way (like adding class and retrieve their name even with jquery).
Upvotes: 0
Views: 7271
Reputation:
<a>, <applet>, <button>, <form>, <frame>, <iframe>, <img>, <input>, <map>, <meta>, <object>, <param>, <select>, and <textarea>
https://developer.mozilla.org/en-US/docs/DOM/element.name
To the best of my knowledge, name is mostly used for pairing elements with labels (and in that vein, grouping radio buttons).
EDIT: Mentioning Mike's comment. Name is also used for form submission with GET and POST in a key/value pair sort of way.
Update: It may be worth looking at this post.
OMG Ponies has some good info on the topic:
My understanding is that when Netscape created Javascript, it used the name attribute. The HTML spec however decided to go with id, but kept name for backwards compatibility. IME, using the name attribute was required for Internet Explorer 6 support because the javascript engine in IE wouldn't read the id attribute - only the name though both were defined.
Upvotes: 2
Reputation: 14564
You can use whatever attribute name you want - but 'name' isn't a valid attribute on the div tag according to the specification, so your markup would technically be invalid.
If as an example, you take this html:
<!DOCTYPE html>
<head>
<title>test</title>
</head>
<body>
<div name="mydiv" class="myclass"></div>
</body>
And validate it here, you'll see that you get this error:
Line 6, Column 41: Attribute name not allowed on element div at this point.
<div name="mydiv" class="myclass"></div>
Upvotes: 5