0

i have a problem on window resize. I should to append one time on resize an element to anather div but it appedn more times. How can i fix it ? Here you can find an example, resize window more time and after that click on first div and you will see the problem :

$(window).on('resize', function() {
    var windowW = $(window).width();

console.log(windowW);
        if(windowW <= 670){
          
           $('.take').on('click touchstart', function(){
                var info = $(this).text();
                $('.add').append('<p>Inormation :'+info+'</p>');
                });

          } else {
            $('.add').empty();

        }
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

<div class="take">Some information </div>
<div class="add"> </div>
Cananau Cristian
  • 436
  • 2
  • 6
  • 30

1 Answers1

1

Just check the width before append

$('.take').on('click touchstart', function(){
  var info = $(this).text();
  var windowW = $(window).width();
  if(windowW <= 670){
    $('.add').append('<p>Inormation :'+info+'</p>');
  } else {
    $('.add').empty();
  }
});    

Example here

Updated

//Disapear when >= 680
 $(window).on('resize', function() {
    var windowW = $(window).width();
    if(windowW >= 680){
        $('.add').empty();
    }
});

Check size want to disapear

Ryuk Lee
  • 720
  • 5
  • 12
  • if size is 680 it should to dessaper. Thats why i want to qrite it on resize. Your answer is on click but i want it on resize and after that click whats mean **after resize you click on** ! – Cananau Cristian May 07 '18 at 08:34