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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:10:23+00:00 2026-06-03T22:10:23+00:00

In many cases, I use jQuery’s awesome datepicker in forms. I wanted a generic

  • 0

In many cases, I use jQuery’s awesome datepicker in forms. I wanted a generic way to apply it without knowing what the id or class of the input would be. I came up with this:

<span id="datePickerChild">
 <input type="text"/>
</span>
<script type="text/javascript">
 $(document.getElementById("datePickerChild").firstChild).datepicker();
</script>

Using the mvc3 framework these inputs get put in with their own ids and such at runtime based on the helpers so I wanted this dynamic approach. Is there a more efficient way to be doing this?

Edit:

Using jQuery 1.4.4

  • 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-03T22:10:25+00:00Added an answer on June 3, 2026 at 10:10 pm

    That seems like a reasonable approach for this. You could probably do it a little more “idiomatically” with jQuery like the following:

    $('#datePickerChild').children().first().datepicker();
    

    Or even:

    $('#datePickerChild > input:first').datepicker();
    

    One point of confusion, however, is that you say you want to do this without having to know what the id of the element is, although you still use an id in the selector. If you’re trying to use that id “generically” (as in it appears several times on the page), you would want to use a class instead. Once you have a class on the element you need, you would just change your selector to something like:

    $('.date-picker-container').children().first().datepicker();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are many cases which are good cases to use multi-thread in
I'd like to use properties for my instance variables, but in many cases, I
I am writing an installer class for my web service. In many cases when
How can I use jQuery to find out how many children an element has?
First of all, there are many cases where Sleep() is misused , for example
I'm using c#. In many cases I'm writing code that can benefit from a
In Python scripts, there are many cases where a keyboard interrupt (Ctrl-C) fails to
In many prototype scripting cases, it's easier to just stick every form item (such
As many of you know, most jQuery (or javascript, for that matter) plugins you
Is there any way in JQUERY to trigger a function when a checkbox has

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.