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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:32:24+00:00 2026-05-24T05:32:24+00:00

I have several inputs which trigger JQuery UI datepickers e.g. <input id=one type=text/> <input

  • 0

I have several inputs which trigger JQuery UI datepickers e.g.

<input id="one" type="text"/>
<input id="two" type="text"/>
<input id="three" type="text"/>
<input id="four" type="text"/>

For each jquery UI datepicker created, I want to assign a custom class based on the ID of the input which triggered it i.e. .one, .two, .three

So if the datepicker is triggered by the first input the resulting HTML will look like:

  <div class="one ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" id="ui-datepicker-div">

Note the first class one

Is this possible? The ‘create‘ method of the datepicker does not seem to work for me…

  • 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-24T05:32:25+00:00Added an answer on May 24, 2026 at 5:32 am

    beforeShow can be used to manipulate the class before showing the datepicker.

    $('input').datepicker({
       beforeShow: function(input, inst) {
           $('#ui-datepicker-div').removeClass(function() {
               return $('input').get(0).id; 
           });
           $('#ui-datepicker-div').addClass(this.id);
       }
    });
    

    Demo (using jQuery 1.6.2 but needs jQuery > v1.4 for the .removeClass() which takes a function)

    Note This works by removing all the classes (i.e. <input> ids) with a **general $('input') selector which you might want to limit to just pick up the <input> elements that have been modified into date pickers.

    Edit Just had an upvote for this and looking at the code, it did not seem to do what I explained it should (maybe I misunderstood the question!). So, here is a version which adds a class equal to the id of the <input> clicked on to the datepicker. Also uses the original .removeClass() so this will work with jQuery > v1.2.

    var inputIds = $('input').map(function() {
        return this.id;
    }).get().join(' '); // space separated ready for removeClass
    
    $('input').datepicker({
       beforeShow: function(input, inst) {
           $('#ui-datepicker-div').removeClass(inputIds);
           $('#ui-datepicker-div').addClass(this.id);
       }
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several input elements which look like this: <input type=radio checked=checked value=1 name=handle[123]
I have several input and option elements on my page, each (well almost) have
I'm using an e-commerce system which allows you to have several variations for each
I have a php script which I need to validate several inputs with. Is
I have a PHP Script which has several text areas. What I would like
I have several html input elements which all look something like this: <input id=1
I have several text fields which compromise a registration form . When the user
I have a piece of jQuery code which invokes several getJSON() calls in quick
I have... a dynamic populated select box several input boxes a submit button form
I have a search form with inputs and selects, and when any input/select is

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.