BOOTSTRAP tooltip for input element only if input length val <n

I would like to show a hint when input.val().length <= 3 then hide the hint when> 3 characters

Check this:

 <input type="text" id="nav-search"/> $('#nav-search').on('keyup',function(){ var _keys = $(this).val(); if(_keys.length <= 3){ $(this).tooltip({'trigger':'focus',position:'right'}); $(this).trigger('focusin'); } }); 

it does not work explicitly: /

+4
source share
2 answers

Theoretically, it should work:

 $("#nav-search").on("keyup", function() { if (this.value.length <= 3) { $(this).tooltip("show"); } else { $(this).tooltip("hide"); } }).tooltip({ placement: "right", trigger: "focus" });​ 

In practice, it works.

DEMO: http://jsfiddle.net/FvxnN/

+8
source
 $('#nav-search').bind('keyup',function(){ var _keys = $(this).val(); if(_keys.length <= 3){ $(this).tooltip({'trigger':'focus',position:'right'}); $(this).trigger('focusin'); }else{ //perform some action } }); 
+1
source

Source: https://habr.com/ru/post/1436121/


All Articles