Simon
Simon

Reputation: 8349

jQuery get HTML value

I have the following HTML code:

<p>Start Date: <span class="text-success" id="subscriptionStartDate">28/01/2015 4:49:43 a.m.</span></p>

How can I retrieve the value of 28/01/2015 4:49:43 a.m. from the element with the id of subscriptionStartDate?

Here is what I have tried:

var startDate = $(".subscriptionStartDate").val();

This is however not getting any value at all.

Thanks in advance.

Upvotes: 0

Views: 69

Answers (3)

Nishit Maheta
Nishit Maheta

Reputation: 6031

Use Jquery .text() or .html()

var startDate = $("#subscriptionStartDate").text();

or

var startDate = $("#subscriptionStartDate").html();

use "#" instead of '.' for id attribute.

Upvotes: 1

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this : you can use .text() or .html(). You can use .val() for input elements having value attribute.

Also correct your jQuery selector to id selector using #

var startDate = $("#subscriptionStartDate").text();

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

Try to use id selector and use .text(),

var startDate = $("#subscriptionStartDate").text();

Upvotes: 4

Related Questions