Using custom HTML attributes for JavaScript purposes?

Posted by user1103990 on Stack Overflow See other posts from Stack Overflow or by user1103990
Published on 2012-12-12T22:47:52Z Indexed on 2012/12/12 23:03 UTC
Read the original article Hit count: 158

Filed under:
|
|

One of my colleagues doesn't like to use HTML classes and ids for javascript/jQuery purpose. Therefore I've seen that he had created custom html attribute such as

<div id="myid" class="cssClasses ..." [some-purpose-id]="mycustomId">...</div>

I asked him if it was really a good idea and he replied that he considers that classes and Ids should be reserved for styling.

Personally, I would have used classes. Some classes would have been used for styling, and some other classes would have been used for programming (jQuery selectors). The idea is to keep things appart also. And of course jQuery could set styling classes but if possible not use them for selection. Of course I also use id when appropriate but since an id is unique on a page, I like to do generic stuff using classes.

I would like to know you opinions on the better approach (if there is one). Thank you.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html