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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:37:35+00:00 2026-06-09T06:37:35+00:00

I have 2 html elements: A and B, here is the jquery code: $(‘A’).click(function(){

  • 0

I have 2 html elements: A and B, here is the jquery code:

$('A').click(function(){
    $('B').click(function(){
        console.log("hello");
    })
})

when I click A and then click B, it will show me “hello”, which is fine.
But when I click A again and then click B, this time it shows me TWO “hello”, which is undesirable. I only want ONE hello.

I more or less know the reason, it might be the result of the callback function: B is still waiting for user to click it after the first click.

now my question is: if I still want “clicking B” inside “clicking A” (“clicking B” is a callback function of “clicking A”), how can I solve the double result problem?

I am new to the callback function, please 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-06-09T06:37:36+00:00Added an answer on June 9, 2026 at 6:37 am

    The problem is, that each consecutive click on A adds another click-handler to your B. Each of these handlers get executed when you click on B. So if you click A ten times, you have bound ten clickhandlers to B 😀

    To avoid the problems of the other solutions, constant un- and rebinding and global variables which both are nasty, use this clean solution instead:

    $('A').one("click", function(){
        $('B').click(function(){
            console.log("hello");
        })
    })
    

    By using .one() instead of click, the click-event on A is triggered only once, binding exactly one click-eventhandler to your element B.

    Example Fiddle

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

Sidebar

Related Questions

I have some JQuery code that converts all HTML elements of a specific class
I have several HTML elements (buttons) that fire the same JQuery AJAX request. When
I have a simple function in jQuery that creates new elements in the DOM.
I have the following jQuery code: $('.save').submit(function(e){ var formElement = $(this); var data =
Have a look at the following code (additionally, you will need jquery.js , jquery.viewport.js
I have following jquery code plugin: (function ($) { $.fn.extend({ collapsiblePanel: function () {
i have html elements <ul> <li> <dl class=details clear> <dt>TIME&nbsp;:&nbsp;&nbsp;&nbsp;</dt> <dd>09:00:00-10:00:00</dd> <dt>Availible&nbsp;Days&nbsp;:&nbsp;&nbsp;</dt> <dd>monday,tuesday,wednesday</dd> <dt></dt>
how can i do. i have many html elements on page. after clicking on
OK, I have two HTML select elements and a button. I need to disable
I have a collection of HTML elements that is structured and hierarchical. When an

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.