tags:

views:

88

answers:

2

My Html Markup is like this

<div id="main">
    <div id="slider">
        <img src=""/>
    </div> 
    <div class="clear slider"></div>

    <div class="slider ndslider">
        <a href="#" rel="bookmark">
            <img src="#" title=""/>
        </a>
    </div>    

    <div class="slider rdslider">
        <a href="" rel="bookmark">
            <img src="" title=""/>
        </a>
   </div>       
<div class="slider thslider nivoSlider">
    <a rel="bookmark" href="" class="nivo-imageLink" >
        <img src="image src" >
    </a>
    <a rel="bookmark" href="" class="nivo-imageLink">
        <img title="" src="">
    </a>
    <a rel="bookmark" href="#" class="nivo-imageLink">
        <img title="" src="">
    </a>
    <div class="nivo-slice"></div>
    <div class="nivo-slice"></div>
    <div class="nivo-slice"></div>
    <div class="nivo-directionNav">
        <a class="nivo-prevNav">Prev</a>
        <a class="nivo-nextNav">Next</a>
   </div>
   <div class="nivo-controlNav">
        <a rel="0" class="nivo-control active">
            <img alt="" src="undefined">
        </a>
        <a rel="1" class="nivo-control">
            <img alt="" src="undefined">
       </a>
   </div>
</div>
</div>

I want to find the all the images inside this DIV

<div class="slider thslider nivoSlider">

</div>

and set that images on to this

<div class="nivo-controlNav">
      <a rel="0" class="nivo-control active">
          <img alt="" src="undefined">
      </a>
</div>

For Doing the same i had written my custom jQuery but it is not working.

jQuery(document).ready(function() {
     jQuery('.thslider a img').each(function(){
            var imgSrc = jQuery(this).attr('src');
            var newSrc = 'http://saorabh-test1.rtcamp.info/wp-content/themes/twentyten/timthumb.php?src='+ imgSrc +' &h=50&w=50&zc=1';
            jQuery(".thslider .nivo-controlNav a img").attr('src',newSrc);

        });
    });

Help me..

A: 
Gaby
I am able to find the image but not able to append it in the other div img src..what i get the image src..var imgSrc = jQuery(this).attr('src');this variable returs what i want but simply if i use this jQuery(".thslider .nivo-controlNav a img").attr('src',imgSrc);it wont work.
if you want you can see it live http://saorabh-test1.rtcamp.info/
@saorabh, added an update that works fine .. plus some explanation of what was wrong .. hope it helps..
Gaby
A: 

You might want to pass imgSrc through encodeURIComponent() before using it as a URI component, also, you have an extra whitespace character after the imgSrc, +' & should be just +'&.

Also your initial selector .thslider a img will give you all the img tags (including the thumbnails), you may want to restrict that selector to .nivo-imageLink img.

Also you are setting the src attribute for ALL the images matched by .thslider .nivo-controlNav a img, not just the image with the same index number.

Put back together:

jQuery(function() { // shortcut for jQuery(document).ready(function() {
  jQuery('.thslider .nivo-imageLink img').each(function (idx) {
     // idx is the index of the image, use the same index for thumbs:
     var $thumb = jQuery(".thslider .nivo-controlNav a img").eq(idx);
     $thumb.attr('src', 'http://saorabh-test1.rtcamp.info/wp-content/themes/twentyten/timthumb.php?src='+ encodeURIComponent(this.src) +'&h=50&w=50&zc=1');
  });
});

Demo on jsfiddle

gnarf
what you are saying is correct but in my case its not working please have a look of this may be it will help you to help me http://saorabh-test1.rtcamp.info/anyway thanks for helping.