开发者

selecting list element in dynamically generated list

 <div id="carat_weight_right" style="margin-top: 15px;float:left;width:444px;border-width:1px 0px 1px 0 ;border-style:solid; border-color:#327B84;padding-top:10px;padding-bottom:33px;*padding-bottom:59px;">

 <fieldset style="padding-left:20px;padding-bottom:10px;width:415px;margin-top:3px;font-size;10px;">

   <--- start auto gen  using js / java third party tool for sliders using the filament slider tool ---->
  <ol class="ui-slider-scale ui-helper-reset" role="presentation">
  <li style="left:0.00%"><span class="ui-slider-label ui-slider-label-show" style="margin-left: -11.5px; ">FAIR</span><span class="ui-slider-tic ui-widget-content" style="display: none;"></span></li>
  <li style="left:25.00%"><span class="ui-slider-label ui-slider-label-show" style="margin-left: -15.5px; ">GOOD</span><span class="ui-slider-tic ui-widget-content"></span></li>
  <li style="left:50.00%"><span class="ui-slider-label ui-slider-label-show" style="margin-left: -15.5px; ">VERY GOOD</span><span class="ui-slider-tic ui-widget-content"></span></li>
  <li style="left:75.00%"><span class="ui-slider-label ui-slider-label-show" style="margin-left: -15px; ">IDEAL</span><span class="ui-slider-tic ui-widget-content"></span></li>
  <li style="left:100.00%"><span class="ui-slider-label ui-slider-label-show" style="margin-left: -30px; ">SIGNATURE IDEAL</span><span class="ui开发者_开发技巧-slider-tic ui-widget-content" style="display: none;"></span></li></ol>


  <--- end auto genereted list ---->

  </fieldset>
  </div>

what i would like to do is to be able to select this < li style="left:100.00%" > and change the span style within the above < li style="left:100.00%" > ?

how can i select the particular < li style="left:100.00%" > and span within the < li style="left:100.00%" > using jquery ?

thanks


The css truncates the decimal points.

$('li').css('left', function(index, value) {
    if (value === '100%') {
        $(this).children('span').css(''); //Do what you wish here
    }
});


If it is always the last one, as in the posted code, you can do something like this:

var theLI = $("ul.ui-slider-scale > li:last")

to get the li. Then to get the span within you can do this:

theLI.find("span")

to get the span. (Note: if you only need the span, these can be combined)

EDIT: if you can't rely on it being last, you'll need to loop through them like so:

$("ul.ui-slider-scale > li").each(function(){
    if($(this).css("left")==="100%"){
        // do your thing, 'this' is your li
    }
});


$('li').filter(function(){
   return $(this).css("left") == "100%";
}).find('span').css("background-color","red");

Take look at this Demo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜