Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5954979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:02:55+00:00 2026-05-22T18:02:55+00:00

this is part of my code: $(‘.toggle_box’).each(function (){ var timeout, longtouch; $(this).bind(‘mousedown’, function() {

  • 0

this is part of my code:

$('.toggle_box').each(function (){ 
    var timeout, longtouch;  
    $(this).bind('mousedown', function() {
        timeout = setTimeout(function() {
            longtouch = true;
        }, 1000);

    $(this).bind('mouseup', function(){
        if (!longtouch) {
            clearTimeout(timeout)
            var state = $(this).find('.switch').attr('data-state');
            if(state == "off"){
                $(this).find('.switch').attr('data-state','on');
            }
            else{
                $(this).find('.switch').attr('data-state','off');
            }
            var choice = $(this).parent();
            ckbmovestate(choice)
        }
        else{
            alert("3")
        };
    });
})
});

when I click an element (mousedown and up) it works fine, but the 2e time I have to double click the element for it to fire. It looks like the second click resets the bind so that the 3e can use it again. just weird.

Here is a demo: Not valid anymore…
It is the orange checkbox 🙂 (please check in safari/chrome)

thank you for your help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:02:55+00:00Added an answer on May 22, 2026 at 6:02 pm

    Checkout the code posted here … http://jsfiddle.net/qv4Ve/2/

    You were binding the mouseup event inside the mousedown event handler. You ought to have to bound them independently of each other.

    $(this).bind('mousedown', function() {
        timeout = setTimeout(function() {longtouch = true;}, 1000);
        console.log("inside mouse down");
    });
    
    $(this).bind('mouseup', function(){
        console.log("inside mouse up");
        if (longtouch === false) {
            clearTimeout(timeout)
            var state = $(this).find('.switch').attr('data-state');
            if(state == "off"){
                $(this).find('.switch').attr('data-state','on');
            }
            else {
                $(this).find('.switch').attr('data-state','off')
            ;}
    
            var choice = $(this).parent();
            ckbmovestate(choice)
        }
        else {
            alert("is a long touch")
        };
    });
    

    The code in the fiddle posted above works the way you want it to …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my gsp view, I have this code : <g:each in=${fileResourceInstanceList} status=i var=fileResourceInstance> <tr
Note : The code in this question is part of deSleeper if you want
It's a part of larger code base, which forces -Werror on gcc. This warning
Recently I have done this part of code. It does work, but select() works
I am trying to learn and writting this part of code. while testing few
I have this part of code: ->filter('username', 'Security::xss_clean') ->filter('url', 'Security::xss_clean') ->filter('text', 'Security::xss_clean') but it
I have this part of code: def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(params[:comment])
I've a method with this part of code: NSDictionary *tmpDict = [self getJsonDictionary]; NSInteger
Do you have any idea why this part of code isn't working: View: <a4j:commandButton
I have a form where people need to submit information. This part of code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.