I have the following HTML.
<a id="SomeLink" title="My Title" href="http://stackoverflow.com">Click Here</a>
I want to disable clicking on this link. Like if there is a way in CSS or Jquery to remove "href" from this link so it is not clickable?
I have the following HTML.
<a id="SomeLink" title="My Title" href="http://stackoverflow.com">Click Here</a>
I want to disable clicking on this link. Like if there is a way in CSS or Jquery to remove "href" from this link so it is not clickable?
Can you try this, Removed link during on ready handler, you can also use the same while in another firing event handler as well.
$(function(){
$("#SomeLink").attr("href", "javascript:void(0);");
});
OR
$(function(){
$("#SomeLink").attr("href", "#");
});
Bind a click handler that does nothing and disables the default action by returning false.
$('#SomeLink').click(function() {
return false;
});
Maybe this will allow you to deal with elements with duplicate IDs:
$('a[id=SomeLink]').click(function() {
return false;
});
When you use an ID selector, jQuery uses getElementById
, which will only find the first element with the ID. Perhaps using the generic attribute selector will bypass that and use a loop that just matches on the ID attribute. If that doesn't work, you may have to write a filter:
$('a').filter(function() {
return this.id == 'SomeLink';
}).click(function() {
return false;
});
This is very simple.Just use attr in Jquery
function disbleLink(){
$("#SomeLink").attr('href','');
}
Links cannot be disabled. Use a button instead.
<button disabled>click me</button>
If you want to prevent the default behavior when clicking a link, you can use e.preventDefault()
$("a").on('click', function(e){
e.preventDefault();
});
You can use the following code in your JS.
$('#link').click(function(e){
e.preventDefault();
});
And this code in your CSS.
#link{
text-decoration:none;
color: #ccc;
}
I found an answer that I like much better on this site.
Looks like this:
$(document).ready(function(){
$("a#SomeLink").click(function () {
$(this).fadeTo("fast", .5).removeAttr("href");
});
});
Enabling would involve setting the href
attribute
$(document).ready(function(){
$("a#SomeLink").click(function () {
$(this).fadeIn("fast").attr("href", "http://whatever.com/wherever.html");
});
});