If i have elements such as this
<img src='0.jpg' id='images' />
<img src='...' id='myEle' />
<img src='...' id='myEle' />
in jQuery can i do something like this
$(document).ready(function() {
$('#myEle').mouseup(function () {
$('#images').attr("src", myEle.getNumber() + ".jpg");
}
}
Obviously each element is sorted in the correct number format that corresponds to the myEle array number
Do not create markup that contains elements with duplicate IDs. This will break things, and you will be mauled by a velociraptor faster than you can say
"goto".Use classes instead:
then…
Re: OP comment
“How do i know which image is pressed?”
Use the
thiskeyword:…I think that’s what you’re looking for.