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!
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
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With