Trigger content modal with JS

Hi, some time ago i added a modal to the Pro header, and used this JS to trigger it:

Query(document).ready(function($) {
	$(".call-dokumenter-liste").click(function(event) {
		 event.preventDefault();
     $("#dokumenter-liste-anchor-toggle").click();
	});
	
});

The buttons have the class “call-dokumenter-liste” and the modal has the ID “dokumenter-liste”

In the header and footer, i can have the href be “#” but in the content, that doesn’t work. I found a way around it, by adding a question mark, instead like this href="?". However, that creates duplicate content, which is of course not desirable. Is there a way to you can help me fix this?

The website is: https://ejendomsdox.dk/

Best,
Johan

Hi There,

Thanks for writing in!

Can you point us the button which you are referring?
I checked the page and all the popups are working fine.

Thanks

Sure, they are working fine right now, because I’m using “?” as the href, but not “#” as it should be. If i change them to “#” they don’t work. I just changed this button for you to test (“Se alle dokumenter”):

Best,
Johan

Hi Johan,

That code works, I just tried it on your site through browser developer console. The problem that I’m seeing is your code is executed even before the content modal or button is created. Please try changing that code to this

jQuery ( document ).on("click", ".call-dokumenter-liste", function(e) {
		 e.preventDefault();
                jQuery("#dokumenter-liste-anchor-toggle").click();
} );

And make sure to add it above other custom scripts.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.