jquery - Using javascript to access li elements within ul -


i trying build program in once page loads automatically adds size. have bunch of li tags within ul , know how access these li tags using jquery.

i use document.getbyname ul not have id.

here complete code:

<div class="exp-pdp-size-dropdown-container selectbox-options exp-pdp-size-dropdown exp-pdp-dropdown selectbox-dropdown-menu" style="display: block; top: 38px; left: 0px;"> <a class="selectbox exp-pdp-size-dropdown exp-pdp-dropdown selectbox-dropdown selectbox-menushowing" style="display: inline-block;" title="" tabindex="0"><label class="exp-pdp-dropdown-label platform-font-1">size</label><span class="selectbox-label">&nbsp;</span><span class="selectbox-arrow glyph-replace" data-glyph="j"></span></a> <ul class="selectbox-options exp-pdp-size-dropdown exp-pdp-dropdown" style=""><li class="exp-pdp-size-not-in-stock selectbox-selected" style=""><a rel=""></a></li><li class="exp-pdp-size-not-in-stock first-in-row upper-left"><a rel="3488377:6">            6         </a></li><li class="exp-pdp-size-not-in-stock"><a rel="3488378:6.5">            6.5         </a></li><li class="last-in-row upper-right"><a rel="3488379:7">            7         </a></li><li class="first-in-row"><a rel="3488380:7.5">            7.5         </a></li><li class=""><a rel="3488381:8">            8         </a></li><li class="last-in-row"><a rel="3488382:8.5">            8.5         </a></li><li class="first-in-row"><a rel="3488383:9">            9         </a></li><li class="exp-pdp-size-not-in-stock"><a rel="3488384:9.5">            9.5         </a></li><li class="last-in-row"><a rel="3488385:10">            10         </a></li><li class="first-in-row"><a rel="3488386:10.5">            10.5         </a></li><li class=""><a rel="3488387:11">            11         </a></li><li class="last-in-row"><a rel="3488388:11.5">            11.5         </a></li><li class="first-in-row"><a rel="3488389:12">            12         </a></li><li class="exp-pdp-size-not-in-stock"><a rel="3488390:12.5">            12.5         </a></li><li class="last-in-row"><a rel="3488391:13">            13         </a></li><li class="first-in-row lower-left"><a rel="3488392:14">            14         </a></li><li class="exp-pdp-size-not-in-stock last-in-row lower-right"><a rel="3488393:15">            15         </a></li></ul></div> 

first, give id <ul> tag, this:

<ul id="mylist" class="selectbox-options exp-pdp-size-dropdown exp-pdp-dropdown" style=""> 

then, use jquery code loop through <li> tags:

<script type="text/javascript">   $(function() {     var listitems = $("#mylist li");     listitems.each(function(i, li) {       var listitem = $(li);       // code     });   }); </script> 

or, if don't want give id <ul> tag, can use class this:

var listitems = $('ul.selectbox-options li'); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -