Roi
Roi

Reputation: 29

jquery changed the image id script

I have this code: http://jsfiddle.net/fGHmF/2/

and its working good. Now I add to each image id the word "size". like this:

<img src='images/size1.png' alt='img1' id='size1' />
<img src='images/size2.png' alt='img2' id='size2' />
<img src='images/size3.png' alt='img3' id='size3' />
<img src='images/size4.png' alt='img4' id='size4' />

because I change the ID the script isn't working anymore: http://jsfiddle.net/6RTr7/

what do I need to change in the script for it to work?

Upvotes: 0

Views: 65

Answers (4)

Scription
Scription

Reputation: 645

You need to the following and it will work

$("#dogSizeBox #size"+id).addClass('border-highlight');

I have added the word "size" right after "#" sign, tested on fiddler and is working.

Upvotes: 0

DEMO

$(document).ready(function(){
    var id = "size2";
    $("#dogSizeBox #"+id).addClass('border-highlight');
})

Upvotes: 0

Kiran
Kiran

Reputation: 20313

Try:

$(document).ready(function(){
    var id = "2";
    $("#dogSizeBox #size"+id).addClass('border-highlight');
});

DEMO FIDDLE

Upvotes: 0

colestrode
colestrode

Reputation: 10668

Update the value of your id variable in your onReady callback:

$(document).ready(function(){
    var id = "size2";
    $("#dogSizeBox #"+id).addClass('border-highlight');
})

Working Demo

Upvotes: 1

Related Questions