Ideal number of identifiers in a dom or html document

I really focused on javascript and improved performance for my site. One thing that I often do is to create elements dynamically and access these elements using ids.

Perhaps you can help me with some questions.

  • What are the main disadvantages in providing each interesting node in a document with a unique identifier?

  • What is the ideal number of identifiers in a document?

  • Is there a maximum number of identifiers for a document?

  • In terms of performance, it turns out that an element of a css class is slower than getting it by identifier?

Thank you guys for your answers. If you have any further comments on these issues about the house and their access, it would be helpful.

Thank.

+5
source share
2 answers

I don't know the real penalty for using id values ​​liberally, except for the annoyance of IE, Safari, and Chrome that push id values ​​to properties window. Good JavaScript code should be able to handle this, however.

Note that:

  • The id values must be completely unique in the document (page). You cannot use the same id value for multiple elements.
  • Searching by "id" is much faster than searching by other means.

, , (, , ..). , , , - . , "id" , .

edit — ( 2013 ) Firefox window "id" .: (

+6
  • id, ( Pointy )
  • ,
  • ( )
  • , - , . , javascript , . CSS, , .

, javascript, . , , , , : , javascript.

, , . , , , id . , AJAX- javascript .

+1
source

All Articles