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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:45:29+00:00 2026-05-31T05:45:29+00:00

I am dynamically creating the options for a select element using jQuery. Is it

  • 0

I am dynamically creating the options for a select element using jQuery. Is it possible in jQuery to setup a function to be executed when that option is selected?

I know I can detect the change of the entire select element, but is it possible to specify this on a per-option basis? Maybe something like this:

$('<option />').onselect(function(){

 // do something

});

Edit:
If it’s not possible to specify a function that get’s executed when a specific option is selected, is it possible to bind a function to an element in jQuery? It would make my logic cleaner by allowing me to just simply execute that function assigned to the option in the .change for the select.

  • 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-31T05:45:30+00:00Added an answer on May 31, 2026 at 5:45 am

    You can delegate a change event to the document and attach an event handler to the select element. This allows for runtime manipulation:

    $(document).on('change', 'select', function() {
        console.log($(this).val()); // the selected options’s value
    
        // if you want to do stuff based on the OPTION element:
        var opt = $(this).find('option:selected')[0];
        // use switch or if/else etc.
    });
    

    Or if you insist on creating functions for each OPTION, you can do:

    $('<option>').data('onselect', function() {
        alert('I’m selected');
    });
    
    $(document).on('change', 'select', function(e) {
        var selected = $(this).find('option:selected'),
            handler = selected.data('onselect');
        if ( typeof handler == 'function' ) {
            handler.call(selected, e);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found out that in FF, if you are dynamically creating an OPTION
i am dynamically creating radio using jquery as shown belown. but they value only
I'm dynamically creating option elements for a drop down menu using Javascript and would
I'm creating a dropdown box dynamically in jQuery by appending html as follows: .append(<br><SELECT
I'm dynamically creating a select node with option nodes inside. The code works fine
Using DTS I'm dynamically creating an access database. After the file is created (which
I have an ASPX page that is dynamically creating a gridview from a database
I have a select box that gets generated dynamically. I want to allow users
I'm creating a page that has some dynamically generated images built from data that
I'm creating the array dynamically using this tool. http://174.121.67.116/~achadire/aware5/product_options.php?cid=6 The array output looks like

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.