3gwebtrain
3gwebtrain

Reputation: 15297

jquery date picker unable to remove the id and set the date picker

In my project, i have a table tr, which has the date picker, on click i am clone the date picker,

And i understand, when i use the same id, will not work for the date picker, so i decide to remove the 'id' but i can't.

How to duplicate the existing 'tr' with date picker to work..

the code I used :

$("table").on("click", function(){
    $(this).find("tr:last").clone(false).removeClass('hasDatepicker').attr('id',"").appendTo($(this)).datepicker();
});


$("input").datepicker();

here is the here is the jsfiddle

Thanks in advance

Upvotes: 0

Views: 448

Answers (1)

Sushanth --
Sushanth --

Reputation: 55750

Your code has couple of problems..

Firstly input element can have the datepicker and not the row. In your code you were trying to add datepicker to the tr element.

Then after cloning and appending the row, you need to search for the input in the row and then add the datepicker to it

$("table").on("click", function () {
    var $this = $(this);
    $this.find("tr:last").clone(false).find('input').removeClass('hasDatepicker')
            .attr('id', "").end().appendTo('table')
    $this.find("tr:last").find('input').datepicker();
});
$("input").datepicker();

Fiddle

Upvotes: 1

Related Questions