Guru Guru - 2 years ago 88
Javascript Question

Jquery set attribute to every element

I want to set attribute of every a tag as img tag's src.

Here is what I did.


But every a tag has same href.

How can I fix this

Answer Source

You should go throught all the images and asign it one by one (That's using your own code). You can do something like:

$(document).ready(function() {
  $(".single img").each(function() {
       var href=$(this).attr('src');

          helpers: {
              title : {
                  type : 'float'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download