Best way to create HTML attribute from CSS class with Javascript
I am working with a server-side framework that will not allow the creation of some new HTML 5 attributes. Though eventually it will be upgraded to allow, I need a temporary fix to insert attributes such as placeholder.
The jsFiddle below creates the attribute with js/jQuery from a pseudo-attribute class.
- Are there any downsides to this method (other than i开发者_如何转开发ts hackishness)
- Is there a better way?
http://jsfiddle.net/luke_charde/HCMUJ/
Well you could use the jQuery "metadata" plugin, which would allow you to migrate your class-based attribute scheme to something like "data-foo" (if you wanted to) later without having to change the JS code.
However I don't see anything particularly wrong with what you've done, though because I'm lazy I'd probably have picked a shorter marker string :-)
精彩评论