How to accept any characters in between * of an getElementById (stack_ * _overflow)?

javascript, jquery

Solution

var elements = document.querySelectorAll('[id^="stack_"][id$="_overflow"]');

Problem

I have a page which changes the ID of input fields every time. So for example if I visit the page now, the ID can be `"stack_15_overflow"` and next time it can be `"stack_293_overflow"`. I want to use a wildcard value for `getElementById`, such as `"stack_ * _overflow"` (where `*` matches anything), to get that value related to any input field starting and ending with some specific text, no matter what text is in between. Code: ``` function HelloId(string){ var name=string document.getElementById('stack_*_overflow').value=name; } ```

Original source

Related problems