javascript - dynamically added elements won't take proper css (js only) -
i have <ul>
element gets it's <li>
's dynamically added, im trying first <li>
bit wider rest width
of 63% while others 60%, reason first 1 gets 60%, idea why?
i can not use css file, has javascript only.
here code:
$('.list').css({ liststyle: 'none', padding: '0', height: '100%', overflowx: 'scroll', }); $('.item-wrapper').css({ background:'#ffffff', width: '60%', margin: '5px', }); $('.item-wrapper').first().css({ width:'63% !important', });
edit: i've failed add resulting markup, here is:
<ul class="list" style="list-style: none; padding: 0px; height: 100%; overflow-x: scroll;"> <li class="item"> <div class="item-wrapper" style="width: 60%; margin: 5px; background: rgb(255, 255, 255);"> <img class="thumbnail" src="images/frame_0001.png" alt="tumbnail" style="width: 25%;"> </div> </li> <li class="item"> <div class="item-wrapper" style="width: 60%; margin: 5px; background: rgb(255, 255, 255);"> <img class="thumbnail" src="images/frame_0002.png" alt="tumbnail" style="width: 25%;"> </div> </li> </ul>
edit 2: i've rearranged ther order .css() functions still no good
it's because of use of !important
, remove it.
it read:
$('.item-wrapper').first().css({ width:'63%', });
other that, syntax fine. approach bit questionable, have requirements elsewhere avoid css.
more on jquery's issue !important
:
http://bugs.jquery.com/ticket/11173
note: since have no concept of precedence play with, ordering significant! i.e. if refactor javascript in way sets width 63% before sets width 60% elsewhere, it'll remain 60%.
Comments
Post a Comment