I have a normal array and each element of this array is one HTML element. when I get HTML element to the array and later change that element(change its class or ....) my array also updates automatically but I don't want this and I want my array to hold old state of html element.
let btn = document.querySelector('.btn') ;
let arr = [] ;
btn.addEventListener('click',function(e){
arr.push(this) ; //now 'arr' is [button.btn]
console.log(arr) ; //[button.btn]
this.classList.add('something') ; //this line will also update 'arr' too but I dont want this and I
//want arr still holds [button.btn]
console.log(arr) ; //[button.btn.something]
})
<!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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<button class="btn">click me</button>
</body>
</html>