jquery - I have an array of URLs that need to be passed into anchor tags -


using pass out array of rgb values , create anchor tags

$.each(color, function(index, value){     $('body').append($('<a class="color">').css({         height: '30px',         width: '30px',         'background-color': value     }) ); }); 

and attempting use code pass array of url's anchor tags

$.each(colorname, function(index, value){     $('.color').each(function(){         $(this).attr('href', value);     }); }); 

sample arrays:

var color = []; color[ 0 ] = 'rgb(233,232,217)'; color[ 1 ] = 'rgb(227,222,202)'; color[ 2 ] = 'rgb(218,210,186)'; color[ 3 ] = 'rgb(208,189,150)'; color[ 4 ] = 'rgb(213,208,194)';   var colorname = []; colorname[ 0 ] = '/url1/'; colorname[ 1 ] = '/url2/'; colorname[ 2 ] = '/url3/'; colorname[ 3 ] = '/url4/'; colorname[ 4 ] = '/url5/'; 

it seems of urls, appends last item in array colorname anchor tags.

try out:- http://jsfiddle.net/adiioo7/l3qrq/

js:-

var color = []; color[ 0 ] = 'rgb(233,232,217)'; color[ 1 ] = 'rgb(227,222,202)'; color[ 2 ] = 'rgb(218,210,186)'; color[ 3 ] = 'rgb(208,189,150)'; color[ 4 ] = 'rgb(213,208,194)';   var colorname = []; colorname[ 0 ] = '/url1/'; colorname[ 1 ] = '/url2/'; colorname[ 2 ] = '/url3/'; colorname[ 3 ] = '/url4/'; colorname[ 4 ] = '/url5/';  $.each(color, function (index, value) {     var anchor=$('<a class="color">').css({         height: '30px',         width: '30px',             'background-color': value     }).attr("href",colorname[index]);     $('body').append(anchor); }); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -