peter.o
peter.o

Reputation: 3530

Do not show title text upon hover on input element

I'm using jQuery Validate plugin and store Error messages in title, e.g.:

<input type="text" name="email" class="required email" title="Bad email format" />

I don't want the title text "Bad email format" to be shown upon hover. How can I disable this function (if it's possible)?

Upvotes: 1

Views: 2218

Answers (2)

Milindu Sanoj Kumarage
Milindu Sanoj Kumarage

Reputation: 2774

Try to use rel="Bad email format" insted title or html data attributes like data-errorMssg="Bad email format" if you cant use them here is an extracted code to hide the title

(function($){  
 $.fn.hide_my_tooltips = function() {  


    return this.each(function() {  

        $(this).hover(function(e) {  
            // mouseover
            var $this=$(this);
            $this.data("myTitle",$this.attr("title")); //store title 
            $this.attr("title",""); 
            }, function() {  
            // mouseout
            var $this=$(this);

            $this.attr("title",$this.data("myTitle")); //add back title
        });

        $(this).click(function() {  
            var $this=$(this);
            $this.attr("title",$this.data("myTitle")); //add back title
        });
    });  
 };  
})(jQuery);

// in document ready function call the JQ function with correct selectors. $("input").hide_my_tooltips();

Upvotes: 1

Rene Pot
Rene Pot

Reputation: 24815

You will need to store the error message somewhere else. For example in a JavaScript array:

var errors = { "emailformat" : "Bad email format" }

And do with it whenever you need it, call it from the array instead of from html.

Upvotes: 0

Related Questions