jQuery datepicker adds a new attribute to the DOM element in IE. if you try to add a new DOM element dynamically copying from an existing element the datepicker will not work in IE as the newly added DOM element refers to the old jQuery attribute. One way to fix this is to delete the attribute and then instantiate the datepicker class on the element. See the following code for the fix.

//newDiv is the new added dom element with innerHTML
jQuery("#newDiv").find(".datePicker").each(function() {
    //removing jquery added attribute as this is causing the dynamically
    // added DOM elem referring old DOM element from it is copied.
    if (jQuery.browser.msie) {
        var jqaddedattr;
        jQuery(this.attributes).each(function() {
            if (this.name.search(/jQuery/) != -1) {
                jqaddedattr = this;
            }
        });
        if (jqaddedattr) {
            jQuery(this).removeAttr(jqaddedattr.name);
        }
    }
    jQuery(this).datepicker({yearRange: '-100:+10', changeFirstDay:false}).val("").trigger('change');
})

6 Comments

  1. Alex says:

    Thanks! I was wondering why the jquery attribute was NULL for my dynamically created fields, then I found this post.

  2. Marlon says:

    Internet Explorer 8 is really good. This browser is very very stable and i have been using it for quite a while without blue screens or crashes.

  3. Hailey Hall says:

    Internet Explorer 8 is very good because it is as stable as Opera. I hate the previous versions of IE like IE6 because it hangs frequently. “

  4. Evie Roberts says:

    Internet Explorer 8 have been my most used browser this year, it is definitely stable and fast loading too. .;

  5. Matt says:

    IE is the worst browser of ALL TIME!

  6. Zachery Beezley says:

    article, worthy to command. I’ve found here exactly what I need to know.

Leave a Reply