Похожие чаты

To see another more problematic scoping issue with var, run

this code on any webpage. It replaces the entire contents with eight buttons. The first four are looped over using var. The next four are looped using let. Try clicking them. Is the alert what you expect?
// DO NOT USE innerHTML! This is solely to make a simple demo!
document.body.innerHTML = "<div class=\"var\"><p>var</p><button>1</button><button>2</button><button>3</button><button>4</button></div><div class=\"let\"><p>let</p><button>1</button><button>2</button><button>3</button><button>4</button></div>";

const varButtons = document.querySelectorAll(".var button");

for (var i = 1; i <= 4; i++) {
varButtons[i-1].addEventListener("click", () => alert(i));
}

const letButtons = document.querySelectorAll(".let button");

for (let i = 1; i <= 4; i++) {
letButtons[i-1].addEventListener("click", () => alert(i));
}

4 ответов

10 просмотров

I still don't get the problem with innerHTML. It's awesome if you just want to insert a string html node inside the element. *I know insertAdjacentHTML exist

Senator
I still don't get the problem with innerHTML. It's...

If you insert *any* user-generated content with innerHTML, you may be susceptible to XSS

MUTHU・KUMAR 「メーカー」 🔺
If you insert *any* user-generated content with in...

But users on the front end can do whatever they want and insert anything anywhere. I only use them to insert content myself in a function for instance

Senator
But users on the front end can do whatever they wa...

Content from one user can XSS another user, for example

Похожие вопросы

Обсуждают сегодня

30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
5
читать файл максимально быстро? странный вопрос))
zamtmn
53
братва! где куличи брать?
Alöscha
25
тоесть, указав return eax, сгенерируется никому ненужная инструкция mov eax,eax ?
Aiwan \ (•◡•) / _bot
24
Посоветуйте пожалуйста аудио плеер для библиотеки mp3- FLAC на компьютере. На Винде пользовался Aimp, в том числе для конвертации. Много нужных команд было прямо в контекст...
Виктор Кузнецов
31
Is FXTL another frax ecosystem token? Why need fxtl when there is already fxs? Why cant I find a straight answer for this? Maybe thats why people think its all so complicated
MBD Tan
11
Hi guys , do we have update on voting?
HB
16
How Much Btc Falling Down ?
Suriya
22
Hi guys ! Anvil is out ! Time for me to stake on capacity. Does someone has a clear tutorial ? I’m thinking about buying a ledger. Is that really possible to stake directl...
Mister Grega
17
я имею в виду официально интегрированный в телегу? в том плане что не сливает переписку с пользователем?
Andrey
9
Карта сайта