javascript - How to move div to for next several divs? -


i have 1 div inside div.

<div id="radnja">     <div id="movethat"></div>   </div>   <div id="radnja">   </div>   <div id="radnja">   </div>   <div id="radnja">   </div>   <div id="radnja">   </div>   <div id="radnja">   </div>   <div id="radnja">   </div>   <div id="radnja">   </div>   <div id="radnja">   </div> 

i want move div 'movethat' next div. want several times depending on how random number in h1 is.

<div id="kocka">   <h1>0</h1> </div> <div id="baci">   <h2>baci kocku</h2> </div> 

h1 random number. jquery.

$(document).ready(function() { $("#baci").click(function() { var rand = math.ceil(math.random()*6); $("#kocka h1").text(rand); }); }); 

help please :)

you should use class not id, following code helpful you

$(document).ready(function() {    $("#baci").click(function() {    var rand = math.ceil(math.random()*6);    for(var = 0;i<rand;i++){      $('#movethat').appendto($('#movethat').parent().next())    }    $("#kocka h1").text(rand); });   });   
.radnja {    width:50px;    height:50px;    border:1px solid #f00;    float:left  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="radnja">      <div id="movethat">222</div>    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>    <div class="radnja">    </div>  <div id="kocka">    <h1>0</h1>  </div>  <div id="baci">    <h2>baci kocku</h2>  </div>


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -