0

I have an weird problem. I'm trying to use jquery hover. But i can't get it to work correctly. The only way i can get i to work is by clicking on it. Are there any who can see there the issue might be? The HTML Part:

<a class="preview"><img id="EquipmentInfoPanelElementUrl" height="100" width="100" src="temp.png" alt="gallery thumbnail" /></a>

The javascript part:

  $("a.preview").hover(function (e) {
            $("body").append("<p id='preview'><img src='" + $("#EquipmentInfoPanelElementUrl").attr("src") + "' alt='Image preview' /></p>");
            $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px").fadeIn("fast");
        },
     function () {
         $("#preview").remove();
     });

        $("a.preview").mousemove(function (e) {
            $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px");
        });
5
  • Is your JavaScript executed at the bottom of the page and/or in a document.ready event handler? Commented Oct 27, 2014 at 12:18
  • also is preview created by javascript as well? Commented Oct 27, 2014 at 12:18
  • It's in document Ready. Commented Oct 27, 2014 at 12:18
  • 1
    Seems fine: jsfiddle.net/pgq7ncx7 Commented Oct 27, 2014 at 12:18
  • I don't think your mousemove is necessary... should be able to do it with just hover and be fine. I don't see your mousemove actually doing anything important, unless I'm wrong... >.> Commented Oct 27, 2014 at 12:20

1 Answer 1

1

It's working. (Latest jQuery library)

<!DOCTYPE html>
<html lang="en">

<head>
  <title>jQuery Autocomplete</title>
  <meta charset="utf-8">
  <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function() {

      $("a.preview").hover(function(e) {
          $("body").append("<p id='preview'><img src='" + $("#EquipmentInfoPanelElementUrl").attr("src") + "' alt='Image preview' /></p>");
          $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px").fadeIn("fast");
        },
        function() {
          $("#preview").remove();
        });

      $("a.preview").mousemove(function(e) {
        $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px");
      });

    });
  </script>
</head>

<body>
  <a class="preview"><img id="EquipmentInfoPanelElementUrl" height="100" width="100" src="http://placehold.it/100x100" alt="gallery thumbnail" /></a>
</body>

</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.