Friday, 15 August 2014

jquery - Copy an image src and place in url -



jquery - Copy an image src and place in url -

i have image in site , want dynamically utilize src background image on inline style on header url.

<div class="banner"><img src="images/image1.jpg" alt="" /></div> <header style="background:url(*image-from-banner*) no-repeat;"></header>

i found code want backwards, can help reverse me.

$('.banner img').each(function(){ var href = $(this).attr('href'); $(this).find('img').attr('src',href); });

you can set background image <header> like:

$('header').css('background-image', 'url(' + $('.banner img').attr('src') + ')');

jquery html

No comments:

Post a Comment