Michael Geary wrote:
The reason your code doesn't work is that you have a single
numBackgrounds
variable shared throughout all the code. You may increment this in a
loop,
but then later on when the .click() callback is called,
numBackgrounds has
already been incremented all the way to 6.
jQuery *is* JavaScript, keep that in mind
$(document).ready(function(){
$(*[id^='bgChangerAnchor').click(function () {
var id = this.id.replace('bgChangerAnchor', '');
$(#mainContainer).css(background,url(backgrounds/
bg_ + id + .jpg));
});
});
MorningZ wrote:
jQuery *is* JavaScript, keep that in mind
That's why I was confused why my loop won't workis there a reason it
doesn't?
$(document).ready(function(){
$(*[id^='bgChangerAnchor').click(function () {
var id = this.id.replace('bgChangerAnchor',
07, 2009 3:58 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: jQuery within Javascript?
MorningZ wrote:
jQuery *is* JavaScript, keep that in mind
That's why I was confused why my loop won't workis there a reason it
doesn't?
$(document).ready(function(){
$(*[id
Is there a missed closing braket and a double quotes after bgChangerAnchor?
$(*[id^='bgChangerAnchor').click(function () {
The reason your code doesn't work is that you have a single numBackgrounds
variable shared throughout all the code. You may increment this in a loop,
but then later on when the .click() callback is called, numBackgrounds has
already been incremented all the way to 6.
Also your loop should
6 matches
Mail list logo