title: Bootstrap 5 : show modal with javascript
body: <p>I'm making a neat gallery with <strong>bootstrap 5</strong>, and I wondered how I could <strong>trigger a bootstrap modal without using &quot;data-bs-...&quot; in my HTML</strong> (to avoid duplicating those data- attributes 50 times).</p>
  <p>I managed to get a full functionning javascript for the  sources, but the .modal() functions and .show() functions don't seem to work. Here's the thing :</p>
  <pre><code>function gallery(_src) {
  var fullPath = _src;
  var fileName = fullPath.replace(/^.*[\\\/]/, '');
  var newSrc = &quot;./assets/img/&quot; + fileName;
  document.querySelector(&quot;div#galleryModal img&quot;).src = &quot;./assets/img/&quot; + fileName;
  
  document.getElementById(&quot;galleryModal&quot;).show(); }
  </code></pre>
  <p>I'm blocked on this last javascript line. The objective : trigger #galleryModal.</p>
  <p>Thanks for reading, thanks for helping !</p>