Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  135] [ 1]  / answers: 1 / hits: 28667  / 14 Years ago, tue, november 23, 2010, 12:00:00

Can I add arbitrary properties to JavaScript DOM objects, such as <INPUT> or <SELECT> elements? Or, if I cannot do that, is there a way to associate my own objects with page elements via a reference property?


More From » dom

 Answers
31

Sure, people have been doing it for ages. It's not recommended as it's messy and you may mess with existing properties.



If you are looping code with for..in your code may break because you will now be enumerating through these newly attached properties.



I suggest using something like jQuery's .data which keeps metadata attached to objects. If you don't want to use a library, re-implement jQuery.data


[#94866] Saturday, November 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;