开发者

how to use jquery each loop in ajax

I need output like below code, where each set of div is coming trough ajax as follows, i am getting div id dynamic as slide1, slide2 via jquery each function. assume that there is no anchor tag at start so how can i get href="#pix1", href="#pix2" ? every time href value is increasing by 1 thanks help is really appreciated

<div id="slide1">
        <ol>
            <li class="firstlist"><a href="#"><b>start</b></a></li>
            <li><a href="#pix1"><img src="images/thumbs/accesories/pic1.jpg"></a></li>
            <li><a href="#pix2"><img src="images/thumbs/accesories/pic2.jpg"></a></li>
            <li><a href="#pix3"><img src="images/thumbs/accesories/pic3.jpg"></a></li>
            <li><a href="#pix4"><img src="images/thumbs/accesories/pic4.jpg"></a></li>
            <li><a href="#pix5"><img src="images/thumbs/accesories/pic5.jpg"></a></li>
            <li><a href="#pix6"><img src="images/thumbs/accesories/pic6.jpg"></a></li>
            <li><a href="#pix7"><开发者_运维问答;img src="images/thumbs/accesories/pic7.jpg"></a></li>
            <li class="lastlist"><a href="#"><b>last</b></a></li>
        </ol>
    </div> <div id="slide2">
        <ol>
            <li class="firstlist"><a href="#"><b>start</b></a></li>
            <li><a href="#pix2"><img src="images/thumbs/accesories/pic2.jpg"></a></li>
            <li><a href="#pix3"><img src="images/thumbs/accesories/pic3.jpg"></a></li>
            <li><a href="#pix4"><img src="images/thumbs/accesories/pic4.jpg"></a></li>
            <li><a href="#pix5"><img src="images/thumbs/accesories/pic5.jpg"></a></li>
            <li><a href="#pix6"><img src="images/thumbs/accesories/pic6.jpg"></a></li>
            <li><a href="#pix7"><img src="images/thumbs/accesories/pic7.jpg"></a></li>
            <li><a href="#pix8"><img src="images/thumbs/accesories/pic8.jpg"></a></li>
            <li class="lastlist"><a href="#"><b>last</b></a></li>
        </ol>
    </div>        

and in jquery i am tring something like as follows


 $("div").each(function(si){
        var slideindex = si+1                               
         $(this).attr('id', 'slide'+slideindex);    
    //I am successful here to get div id slide 0, slide1                
                                    });  


  $('div ol li a').each(function() {

//how should i code here           
        }); 


Like this:

$(this).attr('href');

Inside the loop that is


check this demo.

http://www.balam.in/personal/stackoverflow/each_example.html

You have already done that for div. For anchor, its the same. YOu just need to specify href attribute. Is that you are looking for?

$('div ol li a').each(function(i) {
         var anchorindex = i+1                               
         $(this).attr('href', '#pix'+anchorindex);           
    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜