i have a string which looks like this:
.a,.b,.c,.d
i would like to add a value to an attribute of every one of these
items.
i used this before to add a value to items where i change the height:
$(this).attr("heightwert", parseInt($(this).css('height')));
i use this attribute for sorting.
but if you know how i could sort by the dynamical height of elements this would be great too.
this i use for sorting:
onclick="$('ul.dataa>li').tsort('a',{attr:'heightwert',order:'desc'});"
This was written with the assumption that the
.a,.b,.c,.dwas a reference to the class-names of elements on the page, though reading the comments that follow my posting this answer I’m not sure that this is, indeed, the case. However, on my original assumption, the following seems to do what (I thought) you asked:JS Fiddle demo.
Please note that I’m using the attribute
data-heightwertrather than simplyheightwertas that would be an invalid attribute of an html element, whereas thedata-prefix allows for elements to be assigned/created as necessary by the developer and retain validity of the code. Admittedly this is under html 5, but it’s backwards compatible with html 4.x, and is, at worst, no less valid than simply usingheightwertin such doctypes.The heights of the elements that appear on
:hoverin this demo are reported by the CSS and taken from thedata-heightwertelement as set by jQuery.References:
attr().height().data-custom arbitrary data-storage attributes.