How to do “If Clicked Else ..”

后端 未结 8 1571
灰色年华
灰色年华 2021-01-31 05:48

I am trying to use jQuery to do something like

if(jQuery(\'#id\').click) {
    //do-some-stuff
} else {
    //run function2
}

But I\'m unsure h

8条回答
  •  遇见更好的自我
    2021-01-31 06:38

    You may actually mean hovering the element by not clicking, right?

    jQuery('#id').click(function()
    {
        // execute on click
    }).hover(function()
    {
        // execute on hover
    });
    

    Clarify your question then we'll be able to understand better.

    Simply if an element isn't being clicked on, do a setInterval to continue the process until clicked.

    var checkClick = setInterval(function()
    {
        // do something when the element hasn't been clicked yet
    }, 2000); // every 2 seconds
    
    jQuery('#id').click(function()
    {
        clearInterval(checkClick); // this is optional, but it will
                                   // clear the interval once the element
                                   // has been clicked on
    
        // do something else
    })
    

提交回复
热议问题