How to change content of div on hover using JQuery/Javascript

后端 未结 6 1140
醉酒成梦
醉酒成梦 2021-01-29 16:37

I\'m trying to change the contents of a div when it\'s hovered over using JQuery. I\'ve seen answers on stack overflow, but I can\'t seem to get it working.

I\'ve tried

6条回答
  •  既然无缘
    2021-01-29 17:14

    You cannot call reference a dom with pure Javascript and them manipulate it with jQuery - it will not work.

    Try this:

    $( "#imgDiv" ).mouseover(function() {
          $("#titleDiv").text("hovering");     
    });
    

    The titleDiv id has to be referenced in your code using "#", then the id name.

    Also, use $("#name_of_id").text("your content") instead of .textContent()

提交回复
热议问题