var cDiv = document.querySelector('button'),
el = document.getElementsByTagName('div');
var click = e => {
e = document.createElement('div');
e.setAttribute('class', 'sq');
document.body.appendChild(e);
el = e;
let elX = Math.floor(Math.random() * (151 - 50)) + 50;
let elY = Math.floor(Math.random() * (151 - 50)) + 50;
with(e.style) {
position = 'absolute';
width = elX + 'px';
height = elY + 'px';
background = '#f00';
zIndex = '-1';
border = '2px solid #000';
top = Math.floor(Math.random() * (window.innerHeight - elY)) + 'px';
left = Math.floor(Math.random() * (window.innerWidth - elX)) + 'px';
}
e.addEventListener('click', info);
};
var info = e => {
console.log(e.target);
};
cDiv.addEventListener('click', click);
var doit;
function resizedw() {
if ($(document).width() < 500) {
$('.block').addClass("mobil");
$('.mobil').click(function() {
$(this).css('background', 'blue');
});
} else
$('.block').removeClass("mobil");
};
window.onresize = function() {
clearTimeout(doit);
doit = setTimeout(function() {
resizedw();
}, 0);
};