jquery - Javascript - Block that should disappear on click reappear elsewhere -


i trying 3 squares (put ramdomly) on page disappear on click reason don't understand, of them (usually 2nd or 3rd one) reappear elsewhere on page when click on them.

they should disappear.

i made jsffidle: https://jsfiddle.net/dtchh/9949/

the code:

html

<div class="container">        <div id="square-zone">           <!--           here appear squares           -->         </div> </div> 

javascript

//randomly place squares   $(function() {       var numinfosquares = 3;     var $squarezone = $("#square-zone");     var $toappend = $('<div class="info-square"><span class="square" data-toggle="modal"></span></div>');      (var c = 0; c < numinfosquares; c++) {       $squarezone.append(         $toappend.clone()           .find('.square').attr("data-target", "#myinfomodal" + (c + 1))           .end()       );     };      // place info squares randomly on page     function getrandomint(min, max) {       return math.random() * (max - min + 1) + min;     }     $(".info-square").each(function () {       var topposition = getrandomint(8, 70);         var leftposition = getrandomint(8, 92);        $(this).css({         "top": topposition+"%",         "left": leftposition+"%"       });     });      // clicked squares disappears on click     $(".info-square").click(function () {       $(this).css("display","none");       $(this).next().css("display","block");     });      }); 

css

body {     margin: 10px; }  #square-zone > div { position: absolute; }   .info-square > span {    display: inline-block;   cursor: pointer;   background: url(http://cliparts.co/cliparts/atb/jra/atbjran5c.png) no-repeat center center;   width: 30px;   height: 30px;  } 

how can prevent squares reappear ?

well remove line code makes appear again

$(this).next().css("display","block");   // clicked squares disappears on click $(".info-square").click(function () {      $(this).css("display","none");      //$(this).next().css("display","block"); });  

updated jsfiddle commented line https://jsfiddle.net/dtchh/9950/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -