Reputation: 92
I got a problem with accessing a Div's attribute inside another Div. I'm using the JQuery Plugin QuickFlip and want to change the background image of the back.
<div class="quickFlip">
<div class="blackPanel"> </div>
<div class="redPanel">
<p class="quickFlipCta">Click to Flip</p>
</div>
</div>
This is the structure of one of my panel. (I got more of them all with the same class name). With this code I loaded one of the panels into the variable "div".
$(div).quickFlipper();
div = $(".quickFlip").get().sort(function(){
return Math.round(Math.random())-0.5;
}).slice(0,1);
Now I want to access the background image... I already tried this:
$(div).$('redPanel')({'background': 'url(tiles/' + images[Math.floor(Math.random() * images.length)] + ')'});
which was actually not working... ^^ I was able to change the background of the quickFlip class with this code but not the background of the redpanel...
Hope you guys can help me!
Upvotes: 0
Views: 682
Reputation: 359776
Don't be afraid to use more local variables.
var i = Math.floor(Math.random() * images.length),
bg = 'url(tiles/' + images[i] + ')';
$(div).find('div.redpanel').css('background-image', bg);
Upvotes: 1