I’ve got several buttons that have the same class but apply to different data (albums), so I added an ID to differentiate between them. Because each album has a unique ID, I don’t have to worry about having more than one ID on a page:
<button class="addalbum" id="add<?php echo $a->album_id; ?>">Add album</button>
so the IDs would look like: #add121, #add122, etc.
How do I select one of these ids for a jQuery function? I tried the code below:
var a = $(elm).attr('id');
$('.addalbum' + a).click(function() {
//stuff here
});
Change
to
Since IDs are unique there’s no need to preface it with the class of anything. Also, you need to refer to the id by preceding it with a
#