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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:00:47+00:00 2026-05-23T09:00:47+00:00

I have a form with 2 divs that each contains a set of fields.

  • 0

I have a form with 2 divs that each contains a set of fields.

I would like to do something like this:

$(document).ready( function(){
  $(".sectionBox").click( function(){
      $(this).removeClass('dim');
      $(".sectionBox").not(this).addClass('dim')
  });
});

This works very nicely if the user clicks the div itself or an <input> field. But, it does not work if the user clicks a <select> field – the drop-down appears and my div doesn’t respond at all. How can I ensure they respond:

  1. for select boxes? (required)
  2. for everything? (preferable)

Thanks a lot!


Clarification

Guys, thanks a lot for your responses thus far. I want to simply add .dim to the container div if the div itself or anything inside that div is clicked/focussed on. @LiangliangZheng and @wdm – your solutions seem to add .dim to multiple elements (I just want the container div).

This is where I am at the moment:

$(".sectionBox").click( function(){
    $(this).removeClass('dim');
    $(".sectionBox").not(this).addClass('dim');
});
$("select").focus( function(){
    $(".sectionBox").addClass('dim');
    $(this).parent(".sectionBox").removeClass('dim');
});

This appears to work. Is there anything I should do to make the above more robust?

  • 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-23T09:00:48+00:00Added an answer on May 23, 2026 at 9:00 am

    I make some assumption about your question, here is the code I would suggest:

    $(document).ready( function(){
      $(".sectionBox *").focus( function(){
          var $t = $(this).closest('.sectionBox')
          $t.removeClass('dim');
          $(".sectionBox").not($t).addClass('dim');
        })
        .click(function(){$(this).trigger('focus')});
    });
    

    You can see the fiddle here http://jsfiddle.net/xy8VC/4/

    update:

    $(document).ready( function(){
      $(".sectionBox").addClass('dim');
    
      $(".sectionBox")
      .click( function(){
          $(this).removeClass('dim');
          $(".sectionBox").not(this).addClass('dim')
      })
      $(".sectionBox *").focus( function(){
          $(this).closest(".sectionBox").trigger('click');
        });
    });
    

    http://jsfiddle.net/xy8VC/6/

    First of all, I want to point it out that my 1st attempt would also add ‘dim’ to your container. And if you are happy to adopt the code you found, there are three points I would like to share :

    $(document).ready(function(){
        // Since your containers are not dynamic, wrap 
        // them into an array, so you don't need to call 
        // $() to select the containers every time.
        var $box = $('.sectionBox'); 
        $box.addClass('dim');
    
        $box.click( function(){
            $(this).removeClass('dim');
            $box.not(this).addClass('dim');
        });
        // Also have input included.
        $box.find("select,input").focus( function(){ 
            $box.addClass('dim');
            // Replace parent() with closest() for more 
            // flexibility, unless you are sure that all fields 
            // are direct-children to your container.
            $(this).closest(".sectionBox").removeClass('dim'); 
        });
    });
    

    Try this : http://jsfiddle.net/xy8VC/8/

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

Sidebar

Related Questions

I have a form that contains an n amount divs each of wich contain
I have an ajax form that I would like to submit, and the response
I have form, where some fields are looks like rows, so I can add/delete
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have form like this : <div id='add_field' class='locbutton'><a href='#' title='Add'>Add</a></div> <div id='remove_field' class='locbutton2'><a
I have a set of dynamic headings and hidden divs with the idea that
I have a form and some divs that I modify using jquery. On form
I have a form that has a select menu(A) and 2 divs (B and
I have the following html that when a user selects leasehold additional form fields
I've got a set of product listings that each have a link below them

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.