lundi 30 mars 2015

I need help switching background images with jQuery

I have an unordered list of img url's that are generated with from a custom post type in wordpress.


I have a slider and am using the number of slides to determine which Image url I want as the background for my element.


Sample of generated list:



<ul class="tes-image-links">
<li>http://img-url1</li>
<li>http://img-url2</li>
<li>http://img-url3</li>
</ul>


Sample of my jQuery



$('.cycle-slideshow').find('.cycle-slide').each(function(i){
if ( $(this).hasClass('cycle-slide-active') ){
var apimglink = $('.tes-image-links').children('li').eq(i).text();
$('.ap-testimonial.img-back').css("background" , "'url('"+apimglink+"') !important'" );
}
});


When I use console.log() it spits out the right text that is in the <li> tag, but I can't seem to get this to work.


Aucun commentaire:

Enregistrer un commentaire