Переписать jquery на нативный JS
Как будет выглядеть жикверный скрипт на нативном JS?
$(document).ready(function (){
$( ".dotted" ).each(function() {
$(this).click(function() {
$(this).next('.rekl-close').toggle();
});
});
$( ".rekl-close" ).each(function() {
$(this).find('.rekl-button').click(function() {
$(this).parent('.rekl-close').toggle();
});
});
$('.popup-c section button').each(function() {
$(this).click(function() {
navigator.clipboard.writeText($(this).prev('.token').text())
.then(() => {
// Получилось!
})
.catch(err => {
console.log('Something went wrong', err);
});
});
});
})
Ответы (1 шт):
Автор решения: Илья Яловой
→ Ссылка
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll(".dotted").forEach(function(element) {
element.addEventListener('click', function() {
var nextReklClose = element.nextElementSibling;
if (nextReklClose && nextReklClose.classList.contains('rekl-close')) {
nextReklClose.style.display = (nextReklClose.style.display === 'none') ? 'block' : 'none';
}
});
});
document.querySelectorAll(".rekl-close").forEach(function(element) {
var reklButton = element.querySelector('.rekl-button');
if (reklButton) {
reklButton.addEventListener('click', function() {
element.style.display = (element.style.display === 'none') ? 'block' : 'none';
});
}
});
document.querySelectorAll('.popup-c section button').forEach(function(button) {
button.addEventListener('click', function() {
var tokenElement = button.previousElementSibling;
if (tokenElement && tokenElement.classList.contains('token')) {
var tokenText = tokenElement.textContent || tokenElement.innerText;
navigator.clipboard.writeText(tokenText)
.then(function() {
// Success!
})
.catch(function(err) {
console.log('Something went wrong', err);
});
}
});
});
});