admin管理员组文章数量:1201373
I need to show bootstrap tooltip when user click on element and condition is false. I've written code for this:
<div data-toggle="tooltip" title="You must to log in!" class="stars">425</div>
and Javascript:
$(".statistics .stars").click( function(){
if (! user.isLogin){
$(this).tooltip("show");
setTimeout(function(){
$(this).tooltip( 'hide' );
}, 2000);
}
});
When I don't click I can see default tooltip on hover (I don't need it) and when I click, tooltip don't hide after 2 seconds. How to solve this problems?
I need to show bootstrap tooltip when user click on element and condition is false. I've written code for this:
<div data-toggle="tooltip" title="You must to log in!" class="stars">425</div>
and Javascript:
$(".statistics .stars").click( function(){
if (! user.isLogin){
$(this).tooltip("show");
setTimeout(function(){
$(this).tooltip( 'hide' );
}, 2000);
}
});
When I don't click I can see default tooltip on hover (I don't need it) and when I click, tooltip don't hide after 2 seconds. How to solve this problems?
Share Improve this question asked Jun 21, 2016 at 7:46 Alexander SeredenkoAlexander Seredenko 8193 gold badges11 silver badges26 bronze badges2 Answers
Reset to default 19First you need to set tooltip to be manual, now it will not popup on hover
$('div').tooltip({trigger: 'manual'});
After that you need to save div element before using it inside setTimeout because this
outside of setTimeout and this
inside of setTimeout is different.
$('div').click(function(){
var tt = $(this);
if (! user.isLogin){
tt.tooltip("show");
setTimeout(function(){
tt.tooltip( 'hide' );
}, 2000);
}
});
Here is the updated jsfiddle
This should solve your problem:
$(".statistics .stars").click( function(){
if (! user.isLogin){
var $el = $(this);
$el.tooltip("show");
setTimeout(function(){
$el.tooltip( 'hide' );
}, 2000);
}
});
本文标签: jqueryShow and hide bootstrap tooltip using javascriptStack Overflow
版权声明:本文标题:jquery - Show and hide bootstrap tooltip using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738593550a2101657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论