I would like to show tooltip when input.val().length <= 3
then hide tooltip when > 3 chars
Check this out:
<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 doesn't works obviously :/
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"
});
Practically, it works.
DEMO: http://jsfiddle.net/FvxnN/
$('#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
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With