views:

26

answers:

3

Hi,

I have a

<span id="test">5</span>

and I wand to get its value, 5. And I want to change that value. how do I realize that.

+2  A: 

Get it:

$("#test").text();

Set it:

$("#test").text("New text");

Reference: jQuery API

Bozho
+1  A: 
$('#test').text(); // Gets
$('#test').text('hello'); // Sets

Took about 10 seconds to get into the documentation http://jquery.com and search for "text" and read it...

ApoY2k
A: 

To get it, you probably want the number, so get the .text() and parse it with parseInt(), like this:

var val = parseInt($("#test").text(), 10);

To set it just pass the value to .text(), like this:

$("#test").text(newVal);

You cant test it out here.

Nick Craver