I need to print in the table the values x
and y
and where the button goes.
But how to solve it? I tried creating a function called createTable()
but it doesn't work.
JavaScript code:
function moveBtn() {
var $button = $("#btn");
$button.fadeOut(1000,function(){
var maxLeft = $("#sq").innerWidth()- $button.width();
var maxTop = $("#sq").innerHeight() - $button.height();
var leftPos = Math.floor(Math.random() * (maxLeft));
var topPos = Math.floor(Math.random() * (maxTop));
$button.css({ left: leftPos, top: topPos }).fadeIn(1000);
console.log('x: ' + leftPos + ' y: ' + topPos);
posx.push(leftPos);
posy.push(topPos);
return leftPos, topPos;
});
}
function createtable(posx,posy) {
document.getElementById("#ax").value = posx[i];
}
var posx = new Array();
var posy= new Array();
And his my HTML to generate the table:
<body>
<table align="left" style="padding-left: 900px;" id="tables">
<thead>
<tr style="vertical-align: text-top;">
<th style="padding: 15px;">    X    </th>
<th style="padding: 15px;">    Y    </th>
</tr>
</thead>
<tbody>
<tr>
<td id="ix"><p id="ax"></p></td>
<td id="iy"><p></p id="ay"></td>
</tr>
</tbody>
</table>
<div class="square" id="sq">
<button id="btn" class="btn btn-primary btn-sm" onclick="pressButton();">HazClick!</button>
</div>
Please login or Register to submit your answer