Monday, January 4, 2021

Javascript getElementById based on a partial string

document.querySelector('[id$="MySufixIdString"]').id;

The selector means: get an element where the attribute [id] ending with the string "MySufixIdString".

^ matches the start
* matches any position
$ matches the end