Reputation: 43
I have some code that creates some span tags and each span has its own ID
counter1
counter2
counter4
by its name in the database. Now I'm trying to reach the value of one of them. So, I tried something like this:
var id = // Any number that have a span.
var Counter = $("#counter" + id).val();
alert(Counter);
But, it's just showing "NaN"
Upvotes: 2
Views: 10409
Reputation: 1813
Mmmmm try:
var Counter = $("#counter" + id).html();
or
var Counter = $("#counter" + id).text();
I´m dont sure, but maybe span dont have "value" attribute.
Upvotes: 1
Reputation: 27277
You cannot get a val()
ue of a <span>
. You have to use html()
or text()
.
Upvotes: 2