javascript - Stick ID to the HTML element (using js) instead of id-attribute? -
First post on the Stakeoverflow Hope all is well!
Instead of using the HTML id
attribute, I'm thinking of enclosing an ID value in JavaScript with HTML elements.
For example, say javascript variable htmlElement
is a div then htmlElement.cssName
will tell us its CSS class.
Now, how about
htmlElement.idProperty = "someValue"
idProperty
in event handlers.
this.idProperty
It's easy!
Is there anything wrong with doing this?
EDIT: Thanks for the reply! Very useful and educative, I wish I could check green on them all!
No , if you are dynamically building this item You can use this method, if you are doing it inside of html, then I recommend you to just type the name of html.
However, use a little note element.id instead of IdProperty.
element.id = 'my-id';
Comments
Post a Comment