How to do “If Clicked Else ..”

后端 未结 8 1555
灰色年华
灰色年华 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
    })
    
    0 讨论(0)
  • 2021-01-31 06:44

    This is all you need: http://api.jquery.com/click/

    Having an "else" doesn't apply in this scenario, else would mean "did not click", in which case you just wouldn't do anything.

    0 讨论(0)
提交回复
热议问题