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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:16:54+00:00 2026-06-11T13:16:54+00:00

This question has been asked tons of times, however I don’t see any answer

  • 0

This question has been asked tons of times, however I don’t see any answer for the ‘multiple’ variety:

http://jsfiddle.net/queZ6/107/

When you tab INTO the box, i want to display an alert and capture the focus event. I’m basically wanting to change the highlighting for an element that surrounds each input, that follows along as you fill out the form. It’s basically a signal to the user to easily see what field their on.

I can’t for the life of me figure out how to capture the focus event though tabbing into the box (or also clicking on it obviously).

I dont see why this is difficult, considering you’re typing INTO an input. Cant javascript see the newly created input (that youre typing into) and bind to that? JS is so confusing to me sometimes :S

  • 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-11T13:16:55+00:00Added an answer on June 11, 2026 at 1:16 pm

    Update:

    While the old answer stated that you cannot bind into dynamically created elements(and this is still true to a degree), updates to the plugin in question have made this no longer a problem.

    While the plugin in question still has a problem of triggering the handler multiple times, in the case of an alert message being used, it is now possible to bind to those dynamically created elements thanks to the updates.

    All one must do in order to do this is bind, via .on(), to the chosen:showing_dropdown event on the original targeted select list.

    To solve the problem of the continuously created alert boxes, however, I decided to use underscore.js’s .debounce() method, so it is only triggered once immediately every 1 second.

    The underscore library is by no means required, however you will need to have some sort of debounce function in order to get around that small quirk.

    var debouncedAlert = _.debounce(window.alert, 1000, true);
    $('#select').chosen();
    
    $('#select').on('chosen:showing_dropdown', function(e){
        e.preventDefault();
        e.stopPropagation();
        debouncedAlert('focused');
    });
    

    Working example:

    $(document).ready(function() {
        var debouncedAlert = _.debounce(window.alert, 1000, true);
        $('#select').chosen();
    
        $('#select').on('chosen:showing_dropdown', function(e){
            e.preventDefault();
            e.stopPropagation();
            debouncedAlert('focused');
        });
        
        $('button').click(function() {
            $('#select').trigger('chosen:open');
        });
    
    });
    body {
        margin: 10px;
    }
    
    select {
        width: 200px;
    }
    <link href="https://harvesthq.github.io/chosen/chosen.css" rel="stylesheet"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://harvesthq.github.io/chosen/chosen.jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
    <input type="text" value="Put your cursor here then Press Tab. Chosen will be focused!" style="width:100%">
    <br>
    <select id="select" multiple>
        <option value="1">abc</option>
        <option value="2">def</option>
        <option value="3">ghi</option>
    </select>
    <br>
    <button>Press this button. Now chosen <b>will</b> be focused! :)</button>

    Old answer:

    No, it can’t. Jquery’s regular method of binding will not work with dynamically-created elements. In order to bind to those types of elements, you need .on().

    $('.chzn-choices').focus(function(e){
        e.preventDefault();
        alert('focused!');
    });
    

    Would be changed to:

    $('#select_chzn').on('focus', '.chzn-choices', function(e){
        e.preventDefault();
        alert('focused!');
    });
    

    In this case, you are delegating the event to the container elemen, and then pointing it to your specific element.

    Working example

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

Sidebar

Related Questions

This question has been asked multiple times, however none of the answers seem to
This question has been asked before perhaps multiple times, but I can't get the
Though this question has been asked several times but I really couldn't find any
This question has been asked before (see here and here , for example). However,
I can see that this question has been asked several times, but none of
This question has been asked few times here and there, but you see all
This question has been asked before but i still don't understand it fully so
Maybe this question has been asked many times before, but I never found a
I know this question has been asked a couple of times before. I m
Looks like this question has been asked thousand times already, but each person's configuration

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.