I have 4 divs with a random number inside of them
When calling $("#result1 span").text() the output is blank. However when calling $("#result1 span").html() the output gives the value.
How can I get the value without the html?
The output is like this:
<style type="text/css">
#number {position:relative; top:-225px;left:584px;width:230px;height:10px;}
#number span {padding:14px; margin:2px; color:orange; font-size:30px;}
#number input:hover{opacity:0.9; filter:alpha(opacity=90);}
#number input{opacity:1.0; filter:alpha(opacity=100);}
#generate {position:relative; top:35px; left:-1px; width:95px; height:25px;}
#reset {position:relative; top:35px; left:5px; width:95px; height:25px;}
</style>1
The value I need is right after the closing </style> tag "1"
Full html:
<div id="number">
<span id="result1"></span>
<span id="result2"></span>
<span id="result3"></span>
<span id="result4"></span>
<button id="generate">Generate</button>
<button id="reset">Restart</button>
</div>
Javascript:
$('#result1').html((Math.random() * 10) >> 0);
$('#result2').html((Math.random() * 10) >> 0);
$('#result3').html((Math.random() * 10) >> 0);
$('#result4').html((Math.random() * 10) >> 0);
One thing at least– your selector is wrong. $(“#result1 span”).text() isn’t going to give you anything because there is no span inside result1, result1 is a span. Change your selector to $(“#result1”) and see what you get.
simply changing the selector works for me:
http://jsfiddle.net/ccross59/TnbCc/1/