We wish to have ALL external links within a WordPress site have a simple mouseover tooltip without having to place a title tag or rel or class tag within it. I’ve tried several methods using the $(‘a[href=http]’) selector but can not for the life of me get anything to work.
Here is the code I came up with that does work in a standard HTML page but can’t get it to work within WordPress. In theory this sounds so simple: find all external links and when moused over display this tooltip text…
<script type="text/javascript">
$(document).ready(function() {
var changeTooltipPosition = function(event) {
var tooltipX = event.pageX - 8;
var tooltipY = event.pageY + 8;
$('div.tooltip').css({top: tooltipY, left: tooltipX});
};
var showTooltip = function(event) {
$('div.tooltip').remove();
$('<div class="tooltip">Clicking this link will exit this site.</div>')
.appendTo('body');
changeTooltipPosition(event);
};
var hideTooltip = function() {
$('div.tooltip').remove();
};
$('a[href*=http]').bind({
mousemove : changeTooltipPosition,
mouseenter : showTooltip,
mouseleave: hideTooltip
});
});</script>
ANY help with this would be unbelievably appreciated!
If your code is working in general, but not in WP then this is very likely caused by jQuery being run in no conflict mode by WP.
You will need to use appropriate wrapper to use it as usual (with
$
sign).Here you go:
(change
localhost
with your site address)Thumbnails are retrieved from wordpress.com
I made this originally for a ping listing inside a theme, so if you’re using this for all links, it might be a better idea to create the webshots on mouse over, not directly after document has loaded…