3

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?

0

2 Answers 2

3

You 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');
Sign up to request clarification or add additional context in comments.

3 Comments

Isn't .click() just an alias for .trigger('click')?
@Kirix where are you delcaring your click handler? could you post this in your question?
thanks for answers. Problem was that i triggered click before the default behavior on this click so it just doesn't had anything to show.
1

I did so:

jQuery('#button-show-modal')[0].click();

First index in jQuery object is DOM element: jQuery.get()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.