Bootstrap tooltip not working in chrome - javascript

Bootstrap Tooltip not working in chrome, but working fine in firefox.
<script type='text/javascript'>
jQuery(document).ready(function () {
if ($("[rel=tooltip]").length) {
jQuery("[rel=tooltip]").tooltip({
placement: 'right',
trigger: "hover"
});
}
});
</script>
And also the placement is not working correctly in firefox, even after defining as right, its showing only on top.

You need to update your jQuery to at least 1.7 because it looks like bootstrap 2.2.1 is using .on().
Look at your browser console, it is throwing an error
Uncaught TypeError: Object [object Object] has no method 'on'

Quite an old question but I've been coming across this issue today where none of these answers applied to my problem.
My problem was, that I've been using a tooltip on a disabled button, which is not possible according to the documentation of Bootstrap:
https://getbootstrap.com/docs/4.3/components/tooltips/#disabled-elements
To handle that case, a wrapper element must be used, where the tooltip is applied to. For instance:
<span data-toggle="tooltip" title="Disabled tooltip">
<button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
</span>
Also important is to use the style="pointer-events: none;" attribute on the disabled button. Otherwise it won't be working in Chrome neither. (Firefox seems to deal with it without the wrapper too.)

Related

What's the difference between how firefox clicks and chrome clicks?

I'm having to write a scraper using nightmare. On one the links the website is using a div for the user to navigate away from the page. In order to follow the navigation flow, I would like my nightmare instance to "click" the div. However, nothing happens when I'm on chrome, and obtain the element and call click. Unlike Firefox, where this works fine.
The script
let elem = document.getElementByClassName('is-a-div-element')[0];
elem.click()
Works fine on firefox, nothing happens on chrome! Any ideas? The site causing issue is using React. Not sure if that helps or not.
The HTML structure looks like this.
<div class="nav-element">
<div class="is-a-div-element">
<div roll="button">
<span roll="presentation">Hello World</span>
<span class="Exit">Exit</span>
</div>
</div>
</div>
I'm not sure how Nightmare relates to this issue since you mention Chrome and Firefox and appear to be using standard browser Javascript, but I'll try answer anyway.
Since you've edited your question with more specific information I'll edit my answer. Now the main issue I can see is that you're using getElementByClassName, which isn't a function (missing the s).
Do this instead:
let elem = document.getElementsByClassName('is-a-div-element')[0];
Tested working in Chrome and Firefox:
window.addEventListener('load', function() {
let elem = document.getElementsByClassName('is-a-div-element')[0];
elem.click();
});
<div class="nav-element">
<div class="is-a-div-element" onclick="alert('this was clicked frens');">
<div roll="button">
<span roll="presentation">Hello World</span>
<span class="Exit">Exit</span>
</div>
</div>
</div>

Run Alert when clicking button JS

I am trying to run an alert when clicking at a <a> tag.
$('#login-button1').click(function() {
alert(1234);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a ui-sref="tabsController.inCio" id="login-button1" class="button button-stable button-block LoginButton1" href="#/tabsController/home">Login</a>
Nothing happens when I click the button. I ve tried many other ways to run the alert but none of them seems to have affected the tag.
Console log does not display any error message.
It seems that your project is AngularJS.
If you use AngularJS, you can use ng-click directive.
In HTML:
<a ui-sref="tabsController.inCio" ng-click="alertMethod()" class="button button-stable button-block LoginButton1">Login</a>
In Controller:
$scope.alertMethod = function () {
alert(1234);
}
It is supposed to work, everything looks alright, make sure you have jQuery imported correctly. like:
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
or whatever version of jQuery you are wishing to use, code works fine with above version as seen in this Fiddle

Prototype, jQuery and Bootstrap cause tooltip elements to be hidden on mouse out

I've been working on a project using Prototype, jQuery and Bootstrap. We use Bootstrap Tooltips in our UI, normally over icons and text, as below:
<span class="glyphicon glyphicon-asterisk" data-toggle="tooltip" data-placement="bottom" title="Some tooltip"></span>
<span class="glyphicon glyphicon-asterisk" data-toggle="tooltip" data-placement="bottom" title="Another tooltip"></span>
Link tooltip
We then use some simple Javascript to activate our tooltip:
var _j = jQuery.noConflict();
_j("[data-toggle=\"tooltip\"]").tooltip();
I'm using _j alias of jQuery as the $ prefix is used by Prototype. This works fine, but as soon as you move your mouse from a tooltip'd element, it has style="display: hidden; applied. I can't work out any reasonable explanation, so was wondering if anyone has any ideas?
Here is a jsFiddle.
use this trick to solve the problem:
$('.tooltips').tooltip().on('hidden.bs.tooltip', function(){
jQuery(this).show();
});
You could use display:block !important within your CSS file. Doing this, it will force the element to show, even when the script is telling them to hide.

jQuery UI Dialog - missing close icon

I'm using a custom jQuery 1.10.3 theme. I downloaded every straight from the theme roller and I have intentionally not changed anything.
I created a dialog box and I get an empty gray square where the close icon should be:
I compared the code that is generated on my page:
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<spanid="ui-id-2" class="ui-dialog-title">Title</span>
<button class="ui-dialog-titlebar-close"></button>
</div>
To the code generated on the Dialog Demo page:
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-id-1" class="ui-dialog-title">Basic dialog</span>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" role="button" aria-disabled="false" title="close">
<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">close</span>
</button>
</div>
EDIT
The different parts of the code are generated by jQueryUI, not me so I can't just add the span tags without editing the jqueryui js file which seems like a bad/unnecessary choice to achieve normal functionality.
Here is the JavaScript used that generates that part of the code:
this.element.dialog({
appendTo: "#summary_container",
title: this.title(),
closeText: "Close",
width: this.width,
position: {
my: "center top",
at: ("center top+"+(window.innerHeight*.1)),
collision: "none"
},
modal: false,
resizable: false,
draggable: false,
show: "fold",
hide: "fold",
close: function(){
if(KOVM.areaSummary.isVisible()){
KOVM.areaSummary.isVisible(false);
}
}
});
I'm at a loss and need help.
I am late to this one by a while, but I'm going to blow your mind, ready?
The reason this is happening, is because you are calling bootstrap in, after you are calling jquery-ui in.
Literally, swap the two so that instead of:
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>
it becomes
<script src="js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
:)
Edit - 26/06/2015 - this keeps attracting interest months later so I
thought it was worth an edit. I actually really like the noConflict
solution offered in the comment underneath this answer and clarified
by user Pretty Cool as a separate answer. As some have reported issues
with the bootstrap tooltip when the scripts are swapped. I didn't
experience that issue however because I downloaded jquery UI without
the tooltip as I didn't need it because bootstrap. So this issue never
came up for me.
Edit - 22/07/2015 - Don't confuse jquery-ui with jquery! While
Bootstrap's JavaScript requires jQuery to be loaded before, it doesn't rely on jQuery-UI. So jquery-ui.js can be loaded after bootstrap.min.js, while jquery.js always needs to be loaded before Bootstrap.
This is a comment on the top answer, but I felt it was worth its own answer because it helped me answer the problem.
If you want to keep Bootstrap declared after JQuery UI (I did because I wanted to use the Bootstrap tooltip), declaring the following (I declared it after $(document).ready) will allow the button to appear again (answer from https://stackoverflow.com/a/23428433/4660870)
var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
$.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality
This appears to be a bug in the way jQuery ships. You can fix it manually with some dom manipulation on the Dialog Open event:
$("#selector").dialog({
open: function() {
$(this).closest(".ui-dialog")
.find(".ui-dialog-titlebar-close")
.removeClass("ui-dialog-titlebar-close")
.html("<span class='ui-button-icon-primary ui-icon ui-icon-closethick'></span>");
}
});
I found three fixes:
You can just load bootsrap first. And them load jquery-ui. But it is not good idea. Because you will see errors in console.
This:
var bootstrapButton = $.fn.button.noConflict();
$.fn.bootstrapBtn = bootstrapButton;
helps. But other buttons look terrible. And now we don't have bootstrap buttons.
I just want to use bootsrap styles and also I want to have close button with an icon. I've done following:
How close button looks after fix
.ui-dialog-titlebar-close {
padding:0 !important;
}
.ui-dialog-titlebar-close:after {
content: '';
width: 20px;
height: 20px;
display: inline-block;
/* Change path to image*/
background-image: url(themes/base/images/ui-icons_777777_256x240.png);
background-position: -96px -128px;
background-repeat: no-repeat;
}
This is reported as broken in 1.10
http://blog.jqueryui.com/2013/01/jquery-ui-1-10-0/
phillip on January 29, 2013 at 7:36 am said: In the CDN versions, the
dialog close button is missing. There’s only the button tag, the span
ui-icon is missong.
I downloaded the previous version and the X for the close button shows back up.
I had the same exact issue, Maybe you already chececked this but got it solved just by placing the "images" folder in the same location as the jquery-ui.css
I got stuck with the same problem and after read and try all the suggestions above I just tried to replace manually this image (which you can find it here) in the CSS after downloaded it and saved in the images folder on my app and voilá, problem solved!
here is the CSS:
.ui-state-default .ui-icon {
background-image: url("../img/ui-icons_888888_256x240.png");
}
I know this question is old but I just had this issue with jquery-ui v1.12.0.
Short Answer
Make sure you have a folder called Images in the same place you have jquery-ui.min.css. The images folder must contains the images found with a fresh download of the jquery-ui
Long answer
My issue is that I am using gulp to merge all of my css files into a single file. When I do that, I am changing the location of the jquery-ui.min.css. The css code for the dialog expects a folder called Images in the same directory and inside this folder it expects default icons. since gulp was not copying the images into the new destination it was not showing the x icon.
Even loading bootstrap after jquery-ui, I was able to fix using this:
.ui-dialog-titlebar-close:after {
content: 'X' !important;
position: absolute;
top: -2px;
right: 3px;
}
I'm using jQuery UI 1.8.17 and I had this same issue, plus I had additional css stylesheets being applied to things on the page, including the
titlebar color. So to avoid any other issues, I targeted the exact ui elements using the code below:
$("#mydialog").dialog('widget').find(".ui-dialog-titlebar-close").hide();
$("#mydialog").dialog('widget').find('.ui-icon ui-icon-closethick').hide();
Then I added a close button in the properties of the dialog itself:
...
modal : true,
title: "My Dialog",
buttons: [{text: "Close", click: function() {$(this).dialog("close")}}],
...
For some reason I had to target both items, but it works!
A wise man once helped me.
In the folder where jquery-ui.css is located, create a folder named "images" and copy the below files into it:
ui-icons_444444_256x240.png
ui-icons_555555_256x240.png
ui-icons_777620_256x240.png
ui-icons_777777_256x240.png
ui-icons_cc0000_256x240.png
ui-icons_ffffff_256x240.png
and the close icon appears.
As a reference, this is how I extended the open method as per #john-macintyre's suggestion:
$.widget( "ui.dialog", $.ui.dialog, {
open: function() {
$(this.uiDialogTitlebarClose)
.html("<span class='ui-button-icon-primary ui-icon ui-icon-closethick'></span><span class='ui-button-text'>close</span>");
// Invoke the parent widget's open().
return this._super();
}
});
just add in css
.ui-icon-closethick{
margin-top: -8px!important;
margin-left: -8px!important;
}
If you are calling the dialog() inside the js function, you can use the below bootstrap button conflict codes
<div class="row">
<div class="col-md-12">
<input type="button" onclick="ShowDialog()" value="Open Dialog" id="btnDialog"/>
</div>
</div>
<div style="display:none;" id="divMessage">
<table class="table table-bordered">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Giri</td>
<td>Prasad</td>
<td>25</td>
</tr>
<tr>
<td>Bala</td>
<td>Kumar</td>
<td>24</td>
</tr>
</table>
</div>
<script type="text/javascript">
function ShowDialog()
{
if (typeof $.fn.bootstrapBtn =='undefined') {
$.fn.bootstrapBtn = $.fn.button.noConflict();
}
$('#divMessage').dialog({
title:'Employee Info',
modal:true
});
}
</script>
Just add in the missing:
<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">close</span>
I am having this issue as well. Here is the code that is getting inserted for the close button:
When I turn off the style="display:none:" on the button, then the close button appears. So for some reason that display:none; is getting set, and I don't see how to control that. So another way to address this might be to simply override the display:none. Don't see how to do that though.
I note that the answer posted by KyleMit does work, but makes a different looking X button.
I also note that this issue does not affect all dialogs on my pages, but just some of them. Some dialogs work as expected; other have no title (ie, the span containing the title is empty) while the close button is present.
I am thinking something is seriously wrong and it might not the time for 1.10.x.
But after further work, I discovered that in some cases the titles were not getting set properly, and after fixing that, the X close button reappeared as it should be.
I used to set the titles like this:
('#ui-dialog-title-ac-popup').text('Add Admin Comments for #' + $ac_userid);
That id does not exist in my code, but is created apparently by jquery from ac-popup and ui-dialog-title. Kind of a kludge. But as I said that no longer works, and I have to use the following instead:
$('.ui-dialog-title').text('Add Admin Comments for #' + $ac_userid);
After doing that, the missing button issue seems to be better, although I am not sure if they are definitely related.
I was facing same issue , In my case JQuery-ui.js version was 1.10.3, After referring jquery-ui-1.12.1.min.js close button started to visible.

Bootstrap popover isn't placed correctly even with container: 'body' set

I've got a button in a table which should toggle a popover. I have set the data-container="body" as well as I have tried it with the javascript version.
My popover looks like this: (I have clicked the first button)
My button code is here:
<button id="testsettracesBtn1" class="btn btn-large btn-danger" data-toggle="popover" title="" data-content="And here's some amazing content. It's very engaging. right?" data-original-title="A Title">Click to toggle popover</button>
And here my javascript:
<script type="text/javascript">
$("#testsettracesBtn1").popover({ container: 'body'});
</script>
How can i achieve it to place my popover right? (And yes I have the newest bootstrap version.)
I had the same problem, but the source of the bug was that my Bootstrap framework was outdated. I upgraded to 2.3.2 and the container: 'body' attribute started working.
It caused me quite a headache... until I found out the problem was not in my own code!
This strange behaviour is caused because of many select elements in within my table. I don't know why? I just changed the width of the popover to max-width, after the button is being clicked. With the correct width also the arrow is positioned right:
$(document).ready(function(){
$("[id^=kommentareBtn-]").popover({ container: 'body', placement: 'bottom', html: true });
//this fixed my problem...
$("[id^=kommentareBtn-]").click(function() {
$(".popover").css("width", "276px");
});
});

Categories

Resources