1

I have been tying to perform hover operation on dynamically added input fields.

$( "body" ).delegate( "input", "hover", function(event) {
    alert("ok");
});

Also tried using but works only for static fields.

 $('input').hover(
    function(event) {
        alert("bring tooltip");
    }, 

    function(event) {
        if (hasfocus) {
            alert("Keep the tooltip");
        }
    }
);

Need suggestions.Thanks

koushik
  • 27
  • 5

2 Answers2

0

Firstly, you should be using on().
Secondly, you shouldn't be using a hover event.
Thirdly, delegate to the document, not the body, or preferable just to the closest static parent element.

$(document).on({
    mouseenter : function() {

    },
    mouseleave : function() {
        if ( this === document.activeElement ) {
            // has focus
        }
    }
}, 'input');
adeneo
  • 312,895
  • 29
  • 395
  • 388
0

try this

   $("input").on("hover",function(event){
    alert("bring tooltip");
});
Bahadur Singh Deol
  • 753
  • 2
  • 6
  • 17
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Badacadabra Jun 10 '17 at 12:19