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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:47:51+00:00 2026-05-26T06:47:51+00:00

I have selector with multiple option grouped into option groups. I am trying to

  • 0

I have selector with multiple option grouped into option groups. I am trying to toggle select/deselect of all options when an optgroup label is clicked.

It works fine on initial load, but I also have a functionality that allows me to copy options from one selector to another and back. Once options are copied my toggle stops working.

$("optgroup").toggle(function(){
    $(this).children().attr("selected", "selected");
}, function() {
    $(this).children().attr("selected", false);
});

Here’s the copy/remove script.

  • 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-26T06:47:52+00:00Added an answer on May 26, 2026 at 6:47 am

    This will not give you the desired UX, but it will solve the issue you are having with the toggle events getting unbinded: http://jsfiddle.net/rkw79/SwrVK/9/

    $("select").delegate('optgroup', 'click', function() {
        $(this).toggle(function() {
            $(this).children().attr("selected", "selected");
        }, function() {
            $(this).children().attr("selected", false);
        });
    });
    

    You can either use .live() or .delegate(); the problem is they only work with base events like ‘click’ or ‘hover’, and not derived events like ‘toggle’ (which is why it was wrapped above).

    Note that this solution solves the unbinding issue, but in terms of UX, a few more tweaks are required.

    Updated: UX additions http://jsfiddle.net/rkw79/SwrVK/15/

    I think your intention is to select all the child options when a group is clicked. The code below will do that.

    $("select").delegate('optgroup', 'click', function() {
        $(this).children().attr("selected", "selected");
    });
    

    This chunk of code below will make it so that you can still select each child option independently. Events propagate up the node tree, so you have to prevent it (in this case).

    $("select").delegate('option', 'click', function(e) {
        e.stopPropagation();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an live event on all link or multiple selector on the page
I have a Selenium test case that enters dates into a date selector made
I have a question on how to use a selector with multiple parameters. I
I'm trying to be able to check if a selector have a certain sets
I'm consistently running into an invalid selector exception when I attempt to set multiple
Possible Duplicate: jQuery attribute selector for multiple values I have this $('input:radio[name=foo]').change(function() { blah();
How does one call an @selector method with multiple arguments? I have the following
I have a <select> field. <select name=select-states disabled=disabled><option value=>Choose State &raquo;</option></select> I would like
Let's say that I have a multiple select field like this: <select id=foodlist multiple=multiple>
I have this selector below where it ignores any li with the class show-all-boxes

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.