javascript - How to emulate click event with jQuery? - Stack Overflow

i have simple code:jQuery(document).ready(function(){url = document.location.href.split('#');

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?

Share Improve this question asked May 10, 2013 at 8:40 KinKin 4,59614 gold badges59 silver badges114 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 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');

I did so:

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745085635a4610389.html

相关推荐

  • javascript - How to emulate click event with jQuery? - Stack Overflow

    i have simple code:jQuery(document).ready(function(){url = document.location.href.split('#');

    17小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信