Wrox Home  
Search P2P Archive for: Go

  Return to Index  

html_code_clinic thread: id/name


Message #1 by "Kavanjit" <kavanjit.singh@i...> on Sun, 21 Nov 1999 13:40:42 +0530
> whats diff between id and name attribute in html tags?

This is a great question. On the surface, nothing is different between the
two attributes, however when you look at the DOM or Document Object Model
standard, it becomes apparent that you should be using the ID attribute.
The ID attribute is the chosen way for uniquely identifying an HTML
element in the DOM, as then you can use the DOM properties such as
getElementByID to return a reference to the HTML element. While there is
an equivalent property getElementByName, this is non-standard and was
introduced by IE, but probably won't be supported in the future.

There are one or two occurrences of NAME which differ from the norm as
well, such as in the META tag. Here NAME is used to specify a property for
your web page, such as the author of the document, or associated keywords
with your web page, or a short description of the web page. Also when
using NAME with Forms, I believe that this property is accesible via
script. However, the NAME attribute isn't universal to all elements,
unlike the ID attribute.

Briefly the difference is that using the ID attribute, you can then
reference HTML elements using the DOM, but functionally in HTML the two
attributes (barring the aforementioned one or two elements) are the same
and have the same purpose (to uniquely identify an element on a web page).

Chris

  Return to Index