What i’m trying to do is to select all items where ID attribute starts with a given string but also having a class. For example i have this:
<div id="test-id-1" class="test"></div>
<div id="test-id-2" class="test selected"></div>
<div id="test-id-3" class="test"></div>
so i’m trying using something like this:
jQuery('div[id^="test-id-"].selected').trigger('click');
but it doesn’t work. It should return only the second item in my example. How can i do this?
Many thanks in advance, 🙂
It seems you haven’t been wrapping your code in
document.readywhich means if code is run before the html exists it will not bind handlers to non existent elements. Using thereadyevent wrapper assures that elements exist when code firesReference:
http://api.jquery.com/ready/