0

I am trying to attach a hover function to a dynamic div ID that is being generated by a script (using Smooch api). The function doesn't work even when I run it in my console after everything has been loaded.

I tried doing:

$(document).on("mouseenter", "#messenger-button", function() {
    alert("hey")
});

and I keep getting this error: Uncaught TypeError: Cannot read property 'on' of undefined

The html that is being generated after the Smooch api is initiated looks like this:

<iframe>
 <html>
   <div id="messenger-button" style="background-color: rgb(10, 74, 119);>
 </html>
</iframe>

There is no function that is allowing me to add a class, change the css, or do anything to change the properties for the div in the generated iframe. Can anyone who has used Smooch api tell me how I can add a hover state to the messenger button that is generated?

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
Neha Sohail
  • 239
  • 3
  • 19

1 Answers1

-1

You'll need to select the iframe and get its contents and change the elements from there, see.

$(document).ready(function(){
    var iFrameDOM = $("iframe").contents();

    iFrameDOM.find("#messenger-button").addClass("new-messenger");
});
Kartik Prasad
  • 730
  • 7
  • 18