0

I want to dynamically giving date format using jquery ui.But it doesn't work. My code is

 <table id="sample">
<tr>
    <td>
        Date
    </td>
</tr>

js:

$("#datepicker").datepicker();
 $("#sample tr td").after('<td><input type="text" id="datepicker"/></td>');

fiddle: http://jsfiddle.net/gtwswufu/1/

0

3 Answers 3

2

First append the input and then initialize the plugin:

$("#sample tr td").after('<td><input type="text" id="datepicker"/></td>').queue(function() {
   $('#datepicker').datepicker();
   $(this).dequeue();
})
Sign up to request clarification or add additional context in comments.

Comments

1

You can't intialize the plugins like that, the plugins has to be initialized once the target dom elements are created. So in your case

var $td = $('<td><input type="text" id="datepicker"/></td>').insertAfter('#sample tr td');
$td.find("#datepicker").datepicker();

Demo: Fiddle

Comments

0

HTML

<table>
    <tr>
        <td>
            Date
        </td>
        <td>
            <input name="date" id="datepicker"></input>
        </td>
    </tr>
</table>

JS

$('#datepicker').datepicker();

Fiddle

http://jsfiddle.net/mrd9fpun/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.