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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:55:00+00:00 2026-06-13T02:55:00+00:00

Say I have: <div id=name class=button></div> and in a javacript file I define click

  • 0

Say I have:

<div id="name" class="button"></div>

and in a javacript file I define click actions for both class button and id name, something like:

$("#name").click(function(event){
  alert("hi");
})

$(".button").click(function(event){
  alert("bye");
})

When I click that div, will I get the “hi” alert before the “bye” alert because “hi” appears above “bye”? Or does something else determine what happens first? What if the 2 functions were in different files? Would it then matter which javascript file was included first (appeared closer to the top of the html file)? I assume jQuery has nothing to do with this, right?

  • 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-13T02:55:01+00:00Added an answer on June 13, 2026 at 2:55 am

    You’re absolutely right, that it’s honestly based on which is bound first. In your case, the "#name" one is bound first, then the ".button", so that’s why they are finally executed in that same order. It’s not based on which is seen first on the page, but which is bound first. The binding may occur in a function, so it won’t happen until the function is called (obviously), but the function may be declared before other bindings – doesn’t mean anything, it must be called. Same goes for being in different files. As files are parsed, they are executed. So what I said before applies to this too – as long as the binding executes in the order the things are parsed (from the top of the HTML page to the bottom), they will occur in that order. I’m pretty sure the reason this happens is because jQuery stores these bindings in a stack that is FIFO – first in, first out.

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

Sidebar

Related Questions

Let's say I have this: <div id=wrapper> <pre class=highlight> $(function(){ // hide all links
I have some class like this <div class = student> <div class = name>Adam
say I have a css class name div.TestClass { float:left;etc// } span.SpanTestClass { float:right;etc//
say for example i have 2 div in a div like this <div style=width:
Say I have a loop of objects (style.cover.pic) in a DIV .style_image <div class=style_image>
Say I have a select box eg <div data-bind='visible: someProp'> <select class=selectSubWidgets data-bind='options: subWidgets,optionsText:
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
Say I have 3 models: class Franchises name = models.CharField() class Stores franchise =
Context Let`s say i have: In layout Site.Master: <div class=leftColumn> <asp:ContentPlaceHolder ID=MainContent runat=server />
Let's say you have this Model: //model public class Stuff { public string Name

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.