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

  • Home
  • SEARCH
  • 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 6377691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:54:26+00:00 2026-05-25T01:54:26+00:00

Why does this code would work fine in jQuery 1.5 and not in jQuery

  • 0

Why does this code would work fine in jQuery 1.5 and not in jQuery 1.6? Was there a known change to how jquery creates DOM nodes between these two versions?

var birth = new Date(),
    current = new Date().getFullYear() - 13,
    year = $('select#year'),
    i = 0;
birth.setFullYear(1992, 10, 3);
while (i < 48) {
    var option = $('<option>', { 
        value: current - i,
        text: current - i,
        selected: (current - i === birth.getFullYear()) ? 'selected' : ''
    });
    year.append(option);
    i++;
}

See this working jsfiddle using 1.5 and this non-working jsfiddle using 1.6. The first only selects one option, but the second adds selected="selected" to every option.

Note I’ve only tested this in Chrome at this point.

  • 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-25T01:54:27+00:00Added an answer on May 25, 2026 at 1:54 am
    selected: (current - i === birth.getFullYear()) ? 'selected' : ''
    

    will generate either

    selected="selected"
    

    or

    selected=""
    

    In both of these cases, the browser considers selected set. That’s because selected is a Boolean; Its mere presence signals that it should be selected.

    You should use prop, which was introduced in jQuery 1.6:

    var option = $('<option>', { 
            value: current - i,
            text: current - i
        }).prop('selected', current - i === birth.getFullYear());
    

    http://jsfiddle.net/Z7umc/3/

    Or, if you prefer to have it all within your object:

    var option = $('<option>', { 
            value: current - i,
            text: current - i,
            selected: (current - i === birth.getFullYear())
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know why the same code from this page http://emacsformacosx.com/ would not render
Why does this code not print an exception stack trace? public class Playground {
Why does this code...: NSDictionary *testDictionary = [NSDictionary dictionaryWithObjectsAndKeys:kABOtherLabel, @other, kABWorkLabel, @work, nil]; //
what does this code performs? if(object.jquery){ .... } I don't know what jQuery attribute
I'm new with Objective C. I would like to know why this code does
Probably a simple answer to this. In php, something like this would work fine.
Would this work on all platforms? i know windows does \r\n, and remember hearing
Does this code cause a memory leak: int main(){ int * a = new
Why does this code fail to display the category name Apples using the current
Why does this code: class A { public: explicit A(int x) {} }; class

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.