Is it possible to move an array element with jquery? so if i click on it, it would append in the array aswell and not just visually on the dom?
var cardsInHand = ["1", "2", "3", "4", "5", "6", "7"];
var cardsOnField = [];
const cardsInHandEl = document.querySelector("#cardsInHand-el");
for (var i = 0; i < cardsInHand.length; i++) {
cardsInHandEl.innerHTML +=
`
<button>
${cardsInHand[i]}
</button>
`
}
$(document).on("click", "#cardsInHand-el button", function () {
$("#onField-el button")
.remove()
$(this)
.appendTo($("#onField-el"));
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<ul id="cardsInHand-el">Cards in Hand: </ul>
<ul id="onField-el"></ul>
<script src="script.js"></script>
</body>