Love2c0de Posted October 2, 2013 Share Posted October 2, 2013 Good morning, I have a link on my website which has a default href value. The reason I set an initial value is so that if JS is disabled, it will direct them to another page. My jQuery is supposed to open a 'tooltip' next to the link - which it does - but I want to be able to disable the href so that it points to nowhere so the tooltip activates and the href points to nowhere but can't figure out how to do it. It keeps loading the default page. Here is my code: $(function(){ $("#technologies,#marketing,#google_analytics").fadeIn(2000); $(".tool").attr("href","#"); $(".tool").css("cursor","default"); $(".tool").hover(function(e){ var Xpage = e.pageX; var Ypage = e.pageY; var title = $(this).attr("data-pack"); var div = "<div class='tooltip'>"+title+"</div>"; console.log(div); $("body").append(div); $(".tooltip").css("top", Ypage-90); $(".tooltip").css("left", Xpage+15); $(".tooltip").fadeIn(500); }, function(){ $(".tooltip").remove(); }); }); Thanks for your time. Kind regards, L2c. Link to comment https://forums.phpfreaks.com/topic/282619-jquery-disabling-an-anchor/ Share on other sites More sharing options...
requinix Posted October 2, 2013 Share Posted October 2, 2013 Rather than "disable" the link, add an onclick handler that cancels the event. jQuery? .click(function(e) { e.preventDefault(); }) Link to comment https://forums.phpfreaks.com/topic/282619-jquery-disabling-an-anchor/#findComment-1452123 Share on other sites More sharing options...
Love2c0de Posted October 2, 2013 Author Share Posted October 2, 2013 Good morning, Thanks very much. Works a treat. Regards, L2c. Link to comment https://forums.phpfreaks.com/topic/282619-jquery-disabling-an-anchor/#findComment-1452127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.