Alex Rivera | Logout

Access Multiple Elements of same ID in jQuery

Asked 2011-01-25T04:03:35.043
11

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

Edit
Report

1 Answer

1

If multiple elements will share a certain property, you should assign class to them instead of id. So the resulting jquery code will look something like:

$('.myEle').mouseup();

ID is to be used to uniquely identify elements.

answered 2011-01-25T04:08:26.660

Your Answer