javascript - how to add attribute to each list item -



javascript - how to add attribute to each list item -

i have string looks this:

.a,.b,.c,.d

i add together value attribute of every 1 of these items.

i used before add together value items alter height:

$(this).attr("heightwert", parseint($(this).css('height')));

i utilize attribute sorting. if know how sort dynamical height of elements great too.

this utilize sorting:

onclick="$('ul.dataa>li').tsort('a',{attr:'heightwert',order:'desc'});"

this written assumption .a,.b,.c,.d reference class-names of elements on page, though reading comments follow posting reply i'm not sure is, indeed, case. however, on original assumption, next seems (i thought) asked:

$('.a, .b, .c, .d').attr('data-heightwert', function(i, val) { homecoming $(this).height(); });

js fiddle demo.

please note i'm using attribute data-heightwert rather heightwert invalid attribute of html element, whereas data- prefix allows elements assigned/created necessary developer , retain validity of code. admittedly under html 5, it's backwards compatible html 4.x, , is, @ worst, no less valid using heightwert in such doctypes.

the heights of elements appear on :hover in demo reported css , taken data-heightwert element set jquery.

references:

attr(). height(). data- custom arbitrary data-storage attributes.

javascript jquery string sorting height

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -