Jquery mousedown external js with id set inside hype

Hi everyone, I am working on a project that need to use jquery mousedown event from external javescript. I need to get the element id from where I set it in my hype. My client never using hype before. so that I have to make sure they can use the id in the future? How would I do with that. very appreciated!

//external js
(document).ready(function(){ ("#BtnLight").mouseup(function(){
alert(“test”);
});
});

//#BtnLight
id set inside hype.

Hype uses regular ID’s but the problem is that Hype is “constructed” after the DOMContentLoaded event. Hence you have to fire your code in a Hype specific event listener.

function hypeLoadedCallback (hypeDocument, element, event) {
    $("#BtnLight").mouseup(function(){alert(“test”);});
}

if("HYPE_eventListeners" in window === false) { 
    window.HYPE_eventListeners = Array();
}
window.HYPE_eventListeners.push({"type":"HypeDocumentLoad", "callback":hypeLoadedCallback});
1 Like

Thanks a million. Max!This works perfect! havent worked on hype for quite a long time. brain cell has been killed a lot.

Your welcome and this might also be interesting to you:

1 Like