开发者

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.

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 :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜