my html (всего лишь небольшой раздел)
Код: Выделить всё
Click me to see what rooms your in
[list]
[/list]
< /code>
my javascript (не все) < /p>
const roomsListR = document.querySelector('#roomsList');
const delRoomButTEMPLATE = document.createElement('button')
delRoomButTEMPLATE.classList.add('deleteRoomBtn');
delRoomButTEMPLATE.innerHTML = `Leave this room`;
const fetchRoomsAndProcess = async (event) => {
console.log('fetching rooms')
event.preventDefault();
const response = await fetch('/getRooms');
const jsonResponse = await response.json();
const result = jsonResponse.result
// Preparatory clean of the rooms list
roomsListR.innerHTML = ``
for (let i = 5; i != 0; i--) {
let currentRoom = result.splice(0, 1)
let currentRoom2 = currentRoom[0]
let currentRoom3 = currentRoom2['roomname']
console.log('currentRoom3 : ', currentRoom3);
// Now do the stuff with currentRoom
const li = document.createElement('li');
li.innerHTML = `${currentRoom3} ${delRoomButTEMPLATE.outerHTML}`
li.addEventListener('click', (event) => {
console.log('button clicked.')
const parent = event.target.parentNode
console.log(parent.innerHTML)
})
roomsListR.appendChild(li)
if (result.length == 0) {
break
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... xt-content
Мобильная версия