dr-amira dr-amira -3 years ago 105
jQuery Question

jquery Returning object instead of the value

Please help, this code returns [object Object][object Object] in div text;

var x = $(".2").text(Math.floor((Math.random() * 10))),
z = $(".3").text(Math.floor((Math.random() * 10)));
$(".div").text((x) + (z));

Answer Source

In addition to the other answers pointing out that x and z are objects, and you can access their text like:


If you're trying to do addition with the values instead of concatenate them, you can use parseInt() or Number():

$(".div").text(parseInt(x.text()) + parseInt(z.text()));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download