I need after clicking on the button, to click on the element in the layout.
This works on all platforms and browsers except Safari\IOS.
Here is all the code:
const whatDevice2 = /iPad|iPhone|iPod/.test(navigator.userAgent);
let whatEventUse2 = whatDevice2 ? 'touchstart' : 'click';
let play = document.querySelector('#app-2 .cp-play-icon.cp-play-icon-paused');
let originalId = audioPlay2[index].dataset.originalId;
let elementToClick = document.querySelector(#${originalId});
let audioButton = popupElement2.querySelector('a.popup__description_audio');
audioButton.addEventListener(whatEventUse2, () => {
if (elementToClick.classList.contains('cp-playlist-link_current')) {
play.click();
setTimeout(addIdLi2, 0);
} else {
elementToClick.click();
{ setTimeout(addIdLi2, 0);
}
});
Apparently there is some subtlety that I don’t see, and the ways I found on the internet didn’t help.
If anyone has any knowledge in this matter, please give me advice on what to do or point me in the right direction).
I would be glad to have any information, thank you!
Hi, thanks so much for taking the time to join the dialog))
Yes, I saw that .click() should work without any problem in Safari, but unfortunately it doesn’t work after clicking on the button item.
At first the addEventListener had the ‘click’ event, but I found on the internet that Safari can respond to the touchstart event better than the ‘click’ event.
For this I made a check and addEventListener gets the event depending on the platform it is on.
But, with either touchstart or click all events are handled well except these 2:
So just to be clear - are you testing this on a mobile device?
Okay so your problem isnt in the event, but firing a trigger onto other elements.
What elements (specifically, what type of element) are selected by play and elementToClick? (what happens when you console.log them?)
What events are bound to those elements?
[offtopic] This is probably nothing to do with the issue but a span is not allowed to hold div content. A span is an inline element and can only hold other inline elements (even if you set its display to block). You need to use a div instead of a span. If you have not set the span to display:block (or some other display other than inline) you could find that you have no area to click as the divs overflow the span. However as mentioned it should be a div anyway for valid html.
As I said it’s probably nothing al all to do with the issue but won’t do any harm to fix [/offtopic]