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 8174777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:33:00+00:00 2026-06-06T22:33:00+00:00

I have built a site which requires user to login. Now I have decided

  • 0

I have built a site which requires user to login. Now I have decided to make content available without logging in but some operation require user to login first. The site heavily depends on Javascript. If user click some button, login form should be popped-up.

What I am planning to do is to attach click event with required buttons so as to check if user is logged in.
Previous code:

 $('body').on('click','.editRating',function(){
      // code to edit        
      return false;
   })

This is i am planning. To attach one more event handler to required button to check login.

 $('body').on('click','.editRating',function(){
      if user is not loggedIn{
           popup loginForm
           return false
       }        
 })
  $('body').on('click','.editRating',function(){
      // code to edit        
      return false;
   })

So
does this guarantee execution of event-handlers in the same order as defined?
Is there a more cleaner and safe way of achieving the goal?

  • 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-06-06T22:33:03+00:00Added an answer on June 6, 2026 at 10:33 pm

    You could just put it all in one event handler:

    $('body').on('click','.editRating',function(){
        if user is not loggedIn{
            popup loginForm
            return false
        }        
    
        // code to edit        
        return false;
    })
    

    If that won’t work, then you could take advantage of capture phase vs. bubble phase in event handling to insure that you get the order you want. I believe jQuery only does bubble phase (although I welcome correction if I’m wrong about that, of course). So you will have to ditch the jQuery on() stuff in favor of generic JavaScript addEventHandler() stuff.

    (Note that addEventListener() isn’t in IE 8 or earlier, so if you need to support those browsers then you will need to check for addEventListener() and, if it does not exist, use attachEvent() instead. See the relevant MDN documentation.)

    http://jsfiddle.net/WdtsL/ shows how you might do this (minus the IE 8 support just mentioned). Ancestor element capture phase handlers all fire before the child element bubble phase handlers. So you can put your click event handler that checks for login on the body tag or any outer container in capture phase. Then the individual buttons can handle clicks normally in bubble phase.

    Example HTML:

    <body id="myBody">
    <div id="myDiv">
        Click me!
    </div>
    </body>​
    

    Corresponding example JavaScript:

    var myBody = document.getElementById('myBody');
    var myDiv = document.getElementById('myDiv');
    
    myDiv.addEventListener('click', function() { alert("Bubbling phase!"); }, false);
    myBody.addEventListener('click', function() { alert("Capture phase!"); }, true);
    myBody.addEventListener('click', function() { alert("Also a capture phase!"); }, true);
    myDiv.addEventListener('click', function() { alert("Oh, hey, I'm bubbling phase!"); }, false);​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site built in Ruby On Rails which has many ads in
I have a site, which is being built with Joomla 2.5, and this site
I have a client with a site (built with Kohana framework) which has a
I have built a site using php and want to try keep it one
I have built a site in wordpress and the home page is really screwed
I have already built a site from scratch. It has banning, PM, comments, etc.
I have a Wordpress managed web site at http://www.urbanvision.org.uk/ I have built it and
I am going to be deploying a site i have built in rails 3
I have a very complicated site built on CSS3 that has html elements 3d-transformed,
I have a asp.net web site built with .net 2.0 framework. we recently purchased

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.