NullException
NullException

Reputation: 4510

jQuery text returns NULL

x.html:

<h4> Created: <span id="link-created"></span></h4> --> Date is not printed

Javascript:

var create_date = new Date((data.created)*1000); --> data.created is epoch time
$('#link-created').text(create_date);

Any idea why?

Upvotes: 0

Views: 204

Answers (2)

Mark Pieszak - Trilon.io
Mark Pieszak - Trilon.io

Reputation: 66961

It seems data.created must not be coming up with a Number...

js fiddle

Everything else is correct otherwise.

Upvotes: 0

Nogwater
Nogwater

Reputation: 2797

jQuery doesn't like you passing a non-string to .text(). Try this instead:

$('#link-created').text(create_date.toString());

Oh, and to confirm that data.created isn't the problem, you can do (as a test):

var create_date = new Date();

Upvotes: 1

Related Questions