tags:

views:

53

answers:

3
<span id="leftquota" style="display:none" value="$row[available]">$row[available]</span>

JQuery code:

var left=$('#leftquota').val(); alert(left);

+1  A: 

Because val() takes the value from an input field. value is not a valid attribute of <span>.

You should use .text() since you store the same information as in the value-field inside your <span>.

Example:

var left = $('#leftquota').text();
alert(left);
Morningcoffee
Care to comment on the -1?
Morningcoffee
A: 

Val is not for spans. Use attr("value") instead.

Jan Jongboom
He should not be using the value attribute, since it's not a valid attribute of span. The same information is stored in the body, so he should extract it from there instead.
Morningcoffee
He tries to get the value, there is an attribute for value, so get the value; furthermore: you can add any attribute to HTML tags as you can extend the doctype, so your comment is plain bullshit.
Jan Jongboom
You could, but this would not seem to be the case.
Morningcoffee
+1  A: 
var left=$('#leftquota').attr('value'); alert(left);

is what you want.

The .attr() method gets(or sets) an attribute of a element. So .attr('value') will get the value of the 'value' attribute.

EDIT: As morning coffee pointed out, the same value of the 'value' attribute is given inside the span.

So we should do

var left=$('#leftquota').text(); alert(left);

to get the value.

Also, 'value' is not a valid attribute for the span tag.

dotty