user3810560
user3810560

Reputation: 13

Grabbing text from a span tag

I have some code for Javascript using jQuery, and I've been wondering how to fix an element of it.

var dataGiven = +$("span.cost-in-usd:first-child").text();

However, the span tag is:

<span class="cost-in-usd" data-se="product-usd-value">42</span>

Is there a way of modifying my code in order for it to recognise data-se?

Upvotes: 0

Views: 96

Answers (2)

theLeanDeveloper
theLeanDeveloper

Reputation: 391

The following will return the value of attribute

 $('.cost-in-usd').attr('data-se');

Upvotes: 0

ʰᵈˑ
ʰᵈˑ

Reputation: 11375

Yes, use data.

   var datase = $('.cost-in-usd').data('se');
Some links;

Upvotes: 3

Related Questions