Last active
October 10, 2024 09:23
-
-
Save ms-studio/318bfa853de306089c3e10605656a770 to your computer and use it in GitHub Desktop.
Javascript that interacts with Readymag
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
console.log("trying to interact with Readymag..."); | |
document.addEventListener('click', function (event) { | |
console.log("click intercepted!"); | |
console.log( "click target: " + event.target ); | |
if (event.target.matches('[data-id]')) { | |
// get the data-id of this | |
var dataID = event.target.getAttribute('data-id'); | |
console.log(dataID); | |
if ( dataID == "67062ccd81545925be73f212") { | |
// play audio | |
var audio1 = document.querySelector(" [data-id='6706359bcde82ece0165030a'] video "); | |
audio1.currentTime = 0; | |
audio1.play(); | |
} | |
} else if (event.target.matches('img')) { | |
// the closest ancestor with a data-id | |
console.log("target matches: img"); | |
var dataID = event.target.parentElement.getAttribute('data-id'); | |
console.log("closest id: "+dataID); | |
if ( dataID == "67068af9986fc1e1536aa9e1" ) { | |
// play audio | |
var audio1 = document.querySelector(" [data-id='6706359bcde82ece0165030a'] video "); | |
audio1.currentTime = 0; | |
audio1.play(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Posted this code in the Readymag forum: https://forum.readymag.com/t/targeting-elements-with-js-and-using-external-libraries/1492/8