Как передать клик с текста на кнопку?
Как при клике на "Поделиться" вызывать клик на кнопке share?
.ya-share2 {
display: inline-block;
position: absolute;
top: -5px;
left: -5px;
}
.ya-share2__link_more {
background: none !important;
}
@media (min-width:1200px) {
.ya-share2 {
top: -4px;
left: -3px;
}
}
.button {
font-size: 16px;
line-height: 24px;
padding-left: 23px;
display: inline-block;
font-weight: 400;
color: #262b33;
text-decoration: underline;
position: relative;
cursor: pointer;
}
<script src='https://yastatic.net/share2/share.js'></script>
<span class="button">
<span class="ya-share2" data-curtain data-shape="round" data-limit="0" data-more-button-type="short" data-services="vkontakte,facebook,odnoklassniki,telegram,twitter,viber,whatsapp"></span> Поделиться
</span>
Ответы (2 шт):
Автор решения: Мне без сахара
→ Ссылка
Это на jQuery. Вместо #target пишите класс вашего "Поделится"
$( "#target" ).click(function() {
$('.button').trigger('click');;
});
Автор решения: Pavel Grishaev
→ Ссылка
setTimeout(()=>{ // Имитация готовности DOM
let button = document.querySelector('.button');
button.addEventListener( 'click', e => {
if( e.target !== button ) return;
e.stopPropagation();
button.querySelector('.ya-share2__item_more').click();
})
}, 1000 );
.ya-share2 {
display: inline-block;
position: absolute;
top: -5px;
left: -5px;
}
.ya-share2__link_more {
background: none !important;
}
@media (min-width:1200px) {
.ya-share2 {
top: -4px;
left: -3px;
}
}
.button {
font-size: 16px;
line-height: 24px;
padding-left: 23px;
display: inline-block;
font-weight: 400;
color: #262b33;
text-decoration: underline;
position: relative;
cursor: pointer;
}
<script src='https://yastatic.net/share2/share.js'></script>
<span class="button">
<span class="ya-share2" data-curtain data-shape="round" data-limit="0" data-more-button-type="short" data-services="vkontakte,facebook,odnoklassniki,telegram,twitter,viber,whatsapp"></span> Поделиться
</span>