Name Vs ID Attribute In HTML

Hi Guys,

I am going to point out some of the differences between ID and Name attribute in this article.

Name Attribute

  • Valid only on a, form, iframe, img, map, input, select, textarea
  • Name does not have to be unique
  • Can not be referenced in URL
  • Is referenced in JS with getElementsByName()
  • Shares same name space as id attribute
  • Must begin with a letter
  • Is case sensitive
  • Used on form elements to submit information

Id Attribute

  • Valid on any element
  • Each Id should be unique
  • Can be used as anchor reference in URL
  • Is referenced in CSS or URL with # sign
  • Is referenced in JS with getElementById()
  • Shares same name space as name attribute
  • Must begin with a letter
  • Is case sensitive
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s