Sunday, 15 September 2013

javascript - dynamic width of li based on number of lis in a set -



javascript - dynamic width of li based on number of lis in a set -

i want set dynamic width li(s) based on how many li(s) there in list. illustration if there 18 li(s). each width should 100% / 18 = 5.55%. should if have 3 different sets of ul. tried utilize this.

$('.lesson-nav ul li').width( 100 / $(".lesson-nav ul li").length + '%' );

for unknown reason: script gives width 120% while there 1 li , 27.55% when there 18 lis.

as per documentation:

the difference between .css(width) , .width() latter returns unit-less pixel value (for example, 400) while former returns value units intact (for example, 400px).

so should utilize css(width)

$('.lesson-nav ul li').css("width", 100 / $(".lesson-nav ul li").length + '%' );

javascript jquery

No comments:

Post a Comment