javascript - How to disable anchor element on load using jquery? -
in project , there 1 anchor element follows.
<a href="javascript:void(0);" onclick="<?php if ($logged_uid == 0) { ?>login('mystudyplus','free','topicid8:41');$('#login_msg').show();<?php } else { ?>addtodashboard('mystudyplus','free','topicid8:41');<?php } ?>" class="btndownld" style="margin-left:120px;margin-top:200px;background:#f60098;">try now</a>
i want disable above anchor element when page loads. actully have used removeattr property of jquery. want disable anchor element without removing onclick() event. please me in question.
you you'd keep existing attribute handler. suppose you're talking handler definition, not processing, because that's you're trying prevent.
solution 1: remove attribute completely
$(function(){ $(window).load(function(){ $("a").removeattr("onclick"); }); });
solution 2: change attribute code
$(function(){ $(window).load(function(){ var link = $("a"); var existing = link.attr("onclick"); link.attr("onclick", "return;" + existing); }); });
solution 3: change attribute store definition
$(function(){ $(window).load(function(){ var link = $("a"); var existing = link.attr("onclick"); link.attr("data-onclick", existing) .removeattr("onclick"); }); });
this jsfiddle shows 3 solutions. i've written doesn't change links on page load rather simulates page load clicking link. click of first 3 links first simulate page load , click link again , you'll see of them work.
Comments
Post a Comment