I have, the div
's where id looks like this_div_id_NUMBER
, all div
's has the different NUMBER
part. How I find all div
's just using this_div_id
part of id ?
I have, the div
's where id looks like this_div_id_NUMBER
, all div
's has the different NUMBER
part. How I find all div
's just using this_div_id
part of id ?
you can use querySelectorAll to hit partial attribs, including ID:
document.querySelectorAll([id^='this_div_id'])
the ^ next to the equal sign indicates starts with, you can use * instead, but it's prone to false-positives.
you also want to make sure to use quotes (or apos) around the comapare value in attrib selectors for maximum compatibility on querySelectorAll; in jQuery and evergreen browsers it doesn't matter, but in vanilla for old browsers it does matter.
EDIT: late breaking requirement needs a more specific selector:
document.querySelectorAll([id^='this_div_id']:not([id$='_test_field']));
the not() segment prevents anything ending with _test_field from matching.
proof of concept / demo: http://pagedemos.com/partialmatch/