<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="test" data-click="0" style="width:100px; height: 100px; background: red;"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="index.js"></script>
</body>
</html>
$('#test').on('click', function(){
let x = +$(this).attr('data-click');
if(x==5){
$(this).remove();
}
else{
x++;
$(this).attr('data-click',x);
}
})