Reputation: 97
All I am trying to do is insert today's date into a TD
<script type="text/javascript">
$(document).ready(function(){
var myDate = new Date();
$(myDate).appendTo("#calcShptable td:first");
});
</script>
Just doesn't do anything.. no errors or anything.
Upvotes: 0
Views: 336
Reputation: 5579
You have your value and your element selector reversed. Try
$('#calcShptable td:first').append(myDate.toString()); // Append text, not appendTo()
Upvotes: 1
Reputation: 76003
You've created a date object and what you want to do is create a date string like this:
var today = new Date(),
myDate = today.getDate() + '/' + (today.getMonth() + 1) + '/' + today.getFullYear();
$("#calcShptable td:first").append('<span>' + myDate + '</span>');
Here is a link to some documentation for the JavaScript Date Object (you can create a date in any format you like): http://www.w3schools.com/jsref/jsref_obj_date.asp
Upvotes: 0
Reputation: 78520
You can't just insert a string like it was a node. Make it into a node first:
$(document.createTextNode(myDate)).appendTo("#calcShptable td:first");
Upvotes: 1
Reputation: 148524
<script type="text/javascript">
$(document).ready(function(){
var myDate = new Date();
("#calcShptable td:first").append(myDate.toString());
});
</script>
Upvotes: 2