中に乱数が入った4つのdivがあります
呼び出すとき$("#result1 span").text()
、出力は空白です。$("#result1 span").html()
ただし、出力を呼び出すと値が得られます。
HTMLなしで値を取得するにはどうすればよいですか?
出力は次のようになります。
<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
</style>
必要な値は、終了タグの直後です"1"
完全な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);