Reputation: 231
Im using jquery to try to take the value text in a p tag.
I set up an alert for testing to give me the value and it says "current stack is [object Object]"
My html for this is
<div id="player9">
<div class="player_stats">
<p class="player_name"></p>
<p class="player_action"></p>
<p class="player_money"></p>
</div>
</div>
My alert code is:
alert("current stack is " + $("#player9").children(".player_stats").children("p.player_money"));
if I add .val() it comes back as undefined. These values were set upon page load by:
$(whichseat[seat]).children(".hand").children("p.bet").text(bet);
"whichseat[seat] and bet are based into the function. They are setting correctly.
If I use firebug and checkout that specific p tag it says:
<p class="player_money">60000</p>
How do I correctly grab that value?
Any help would be greatly appreciated!
Upvotes: 4
Views: 30162
Reputation: 19353
You can use the text()
method. The val() method is used for getting input field's values. So, you will have:
alert("current stack is " + $("#player9").children(".player_stats").children("p.player_money").text());
Upvotes: 2
Reputation: 724502
Not sure what else I'm missing, but since you're setting the inner text with .text()
, you get it using the same method.
If all else fails you may have to specify to get the inner text of exactly one element:
$("#player9 > .player_stats > p.player_money:first").text()
Upvotes: 1
Reputation: 9719
You could use .html()
or .text()
alert("current stack is " + $("#player9").children(".player_stats").children("p.player_money").html());
Or:
alert("current stack is " + $("#player9").children(".player_stats").children("p.player_money").text());
Obviously the text method will grab just the text, where as the html will get the markup as well. Demo Here
Upvotes: 8