Custom attributes – Yea or nay?

I know people are against it, but I came up with a super short solution for this. If you want to use a custom attribute like “mine” so for example:

<a href="https://stackoverflow.com/questions/992115/test.html" mine-one="great" mine-two="awesome">Test</a>

Then you can run this code to get an object back just like jquery.data() does.

var custom_props = {} ;
$.each($(".selector")[0].attributes, function(i,x) {
    if (this.specified && x.name.indexOf("mine-") !== -1) 
        self.new_settings[x.name.replace("modal-","")] = x.value;
});

Leave a Comment

tech