Easiest way to do this is to define the modal so it triggers on a class, you can then trigger the modal by triggering a click on the class via your code.
Thanks. I’ve added something simple to trigger a click using document.addEventListener(‘DOMContentLoaded’, etc but the modal doesn’t appear?
The site is here and I have added the click event to the copyright bar at the bottom of the page
Hi
I could not find your code to trigger the click, but I did my own test. I created a modal using a custom element click on the class ‘launch’. I then used the following code to test
<p class="triggertest" >Lets do a simple trigger test</p>
<script>
document.querySelector('.triggertest').onclick = function() {
jQuery(".launch").trigger("click");
};
</script>
The above code detects a click in the text ‘Lets do a simple trigger test’ and then launches the modal by triggering a click on the class ‘.launch’. Sorry not sure what the JS is but worked without issue using jQuery. Obviously you would just need to use the trigger line where you need it.
Ah sorry. Thanks for the pointer. I was using document.addEventListener(‘DOMContentLoaded’, function (){//clicker} which wasn’t working, but it worked with: window.onload = function() {//clicker}
It’s now working! Thanks
-
This reply was modified 2 years, 2 months ago by
piersrr.