-1

How do I get an element by id in javascript, kinda like this:

document.getElementById('assistance').style.display = 'none';

If the element id is defined in twig like this:

<div id="assistance-{{ key }}">

1 Answers1

0

Assuming that

  • You will only have one element with id starting with assistance and
  • You don't know what id will be generated

You can use document.querySelector with attribute-starts-with match

document.querySelector('[id^="assistance--"]').style.display = 'none';
gurvinder372
  • 66,980
  • 10
  • 72
  • 94