Здравствуйте! есть простая задача: при нажатии на кнопку свойство width картинки увеличивается в 2 раза, но оно не видит значения передаваемые в width
<!DOCTYPE html>
<html lang="ru">
<head>
<title>dwd</title>
</head>
<body>
<img
id="img"
style="width: 250px"
src="https://biogr.net/wp-content/uploads/2021/04/Screenshot_11.jpg"
alt="5y"
/>
<p id="p"></p>
<button
id="button"
type="submit"
style="position: absolute; left: 800px; top: 200px; display: inline"
>
ТЫЧ!!!
</button>
<script defer>
let valueofpxsizeimg = Number(
document.querySelector("#img").style.width[0] +
document.querySelector("#img").style.width[1] +
document.querySelector("#img").style.width[2]
);
let button = document.querySelector("#button");
document.write('"' + String(valueofpxsizeimg * 2) + "px" + '"');
button.addEventListener("click", function () {
document.querySelector("#img").style.width =
'"' + String(valueofpxsizeimg * 2) + "px" + '"';
});
</script>
</body>
</html>
Ответы (1 шт):
Автор решения: Alexandr_Yakovlev
→ Ссылка
Просто уберите кавычки:
document.querySelector("#img").style.width = String(valueofpxsizeimg * 2) + "px";