Get Position
Use the position
and fen
methods to retrieve the current position of the board.
HTML
<chess-board
style="width: 400px"
position="start"
draggable-pieces>
</chess-board>
<button id="showPositionBtn">Show position in console</button>
JavaScript
const board = document.querySelector('chess-board');
document.querySelector('#showPositionBtn').addEventListener('click', () => {
console.log('Current position as an Object:');
console.log(board.position);
console.log('Current position as a FEN string:');
console.log(board.fen());
});