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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -