Select elements with id attribute that starts/ends with a particular value

Yes it can, you can combine the attribute starts with and the attribute ends with selector

$('[id^="item"][id$="2"]').html("D");

FIDDLE (and you have to enable jQuery in the fiddle)

you can’t use regex to match the numbers in between though, for that you’d need filter()

$('[id^="item"]').filter(function() {
    return this.id.match(/item\d+_2/);
}).html("D");

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)