Last active
July 10, 2022 17:22
-
-
Save koras/2082dffe37dcc557ffc7d032227070ee to your computer and use it in GitHub Desktop.
Скрипт открытия картинки при клике на картинку в статье
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" > | |
// получаем все картинки в статье | |
let elems = document.querySelectorAll('.com-content-article img'); | |
// перебираем все картинки в статье | |
for (let elem of elems) { | |
// удаляем атрибут onmouseout | |
elem.removeAttribute("onmouseout"); | |
// удаляем атрибут onmouseover | |
elem.removeAttribute("onmouseover"); | |
// Если по элементу будет клик, мы откроем новое окно с картинкой | |
elem.onclick = function() { | |
console.log('clicked'); window.open(elem.src, "_blank") | |
}; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dsf