0

I have the following mouseover function:

$('.msg_id').live("mouseover", function() {
    $(this).css('cursor', 'pointer');
    tid = $(this).attr('id');
    idx = $(this).attr('name');
    resp=""; 
    
    $.ajax({
        async: false, 
        url: "log_msg.asp",
        data: $("#msgForm").serialize() + "&aktion=popup&msg_id="+tid+"&msg_id"+idx,
        success: function(data){
            $("#"+tid).html(data);   
        }
        });

    //$.post("log_msg.asp", $("#msgForm").serialize() + "&aktion=popup&msg_id="+tid+"&msg_id"+idx,
        //function(data) {          
          
        //}).success(function(){
            //$("#"+tid).html(data);     
             //resp=data;
             //$('#bub'+tid).css('display', 'block');   
             //popd.css('display', 'block');    
            //});
    });

It puts some html code inside .msg_id ( $("#"+tid).html(data); ). The function mouseover is called in a loop. The ajax request is sent all the time while mouseovering it, not only once. How can I fix it? I have also tried mouseenter, but it fires in a loop too.

3
  • I don't get it. Why are you using mouseover for this? Why not click? Commented Sep 2, 2011 at 15:43
  • does it's something happening under the mouse cursor after the putting html content? Commented Sep 2, 2011 at 15:46
  • i'm usin mouseover because i want the events fire while mouseovering it , not whiole clicking it. Commented Sep 2, 2011 at 15:57

2 Answers 2

2

You might want to use the mouseenter() event instead, as mouseover will fire upon every move inside the element.

$('.msg_id').live("mouseenter", function() {
    //Do work here
});

or if live isn't required, simply:

$('.msg_id').mouseenter(function() {
    //Do work here
});

MouseOver():

  • Will fire upon entering an element can fire inside of any child elements.

MouseEnter():

  • Will fire upon entering an element, and only that element.
Sign up to request clarification or add additional context in comments.

7 Comments

where did you get those descriptions? they validate the confusion around what they actually do...
It's not necessary, was just mimicking it as OP used a live event in his. I'll include a non-live version as well.
ahh, didn't notice they used live.
The descriptions are from the jQuery documentation.
yeah, they need to have better explanations, it sounds like mouseover should work fine for the OP from that description.
|
1

You want to use mouseenter

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.