In an attempt to target a modal without an id or class, I am faced with a challenge. This is because the team page in our CMS assigns a unique
data-modal="NAME-I-WILL-NOT-KNOW"
for each team member added.
The "NAME-I-WILL-NOT-KNOW"
part of the code is controlled by the CMS.
For example: If a client adds a new team member named "Bob Smith", the resulting HTML code will be:
Button
<div class="button-wrap">
<a rel="modal:open" class="button is-danger is-rounded modal-button" data-modal-target="bobsmith" aria-haspopup="true">
<span>View Profile</span>
</a>
</div>
Modal
<div id="modalopen" class="modal" data-modal="bobsmith">
</div>
I have attempted various methods using document.querySelector
, but none seem quite right. The following seems like a step in the right direction.
var modal = document.querySelector("[data-modal=" + target + "]");
Unfortunately, this method does not work as expected.
I've excluded the CMS elements in this demo for clarity purposes.
I thought that sharing the CSS and HTML structure would help explain my issue better.