I find myself doing this a lot, for specific properties for animation purposes, and specially when I’m generating something using database values obtained through PHP. Is there a reason not to do this.
Some sample code, to clear up ambiguity.
This would be the JQuery:
$('.class').each(function(){
var my_new_width = $(this).attr('id');
$(this).stop(false, true).animate({width: my_new_width}, 100);
});
HTML would be:
<img id='100' src='path'/>
Obviously this code offers no functionality, and is meant to be used with a .hover() or something. Just wanted to clear up the ambiguity in the question.
According to W3C id’s must begin with a letter, not that I expect it to blow up if you don’t. In HTML5 you will have the
data-prefix to use when trying to embed data.See this SO question for more discussion and information: Custom attributes – Yea or nay?
Personally, I prefer to use the
relattribute… for some reason it feels right to me… even though its wrong and not w3c compliant.