i have simple code:
jQuery(document).ready(function(){
url = document.location.href.split('#');
if(url[1] === 'button-show-modal'){
console.log('true');
jQuery('#button-show-modal').click();
}
)
So when page is loaded i see in console true, but no modal appears... If i run jQuery('#button-show-modal').click();
by myself modal appears as it should so generally click
event doesn't appear. Where could be the problem?
i have simple code:
jQuery(document).ready(function(){
url = document.location.href.split('#');
if(url[1] === 'button-show-modal'){
console.log('true');
jQuery('#button-show-modal').click();
}
)
So when page is loaded i see in console true, but no modal appears... If i run jQuery('#button-show-modal').click();
by myself modal appears as it should so generally click
event doesn't appear. Where could be the problem?
2 Answers
Reset to default 3You want to trigger the click in jQuery. The code below is assuming you actually have a click event handler in place already on the element.
jQuery('#button-show-modal').trigger('click');
I did so:
jQuery('#button-show-modal')[0].click();
First index in jQuery object is DOM element: jQuery.get()