PHP code:
<a id="a$id" onclick="check($id,1)" href="javascript:void(0)" class="black">Qualify</a>
I want to remove the onclick="check($id,1)
so the link cannot be clicked or "check($id,1)
won t be fired. How can I do it with JQuery?
PHP code:
<a id="a$id" onclick="check($id,1)" href="javascript:void(0)" class="black">Qualify</a>
I want to remove the onclick="check($id,1)
so the link cannot be clicked or "check($id,1)
won t be fired. How can I do it with JQuery?
Old Way (pre-1.7):
$("...").attr("onclick", "").unbind("click");
New Way (1.7+):
$("...").prop("onclick", null).off("click");
(Replace ... with the selector you need.)
// use the "[attr=value]" syntax to avoid syntax errors with special characters (like "$")
$( [id="a$id"] ).prop( onclick ,null).off( click );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a id="a$id" onclick="alert( get rid of this )" href="javascript:void(0)" class="black">Qualify</a>
I know this is quite old, but when a lost stranger finds this question looking for an answer (like I did) then this is the best way to do it, instead of using removeAttr():
$element.prop("onclick", null);
Citing jQuerys official doku:
"Removing an inline onclick event handler using .removeAttr() doesn t achieve the desired effect in Internet Explorer 6, 7, or 8. To avoid potential problems, use .prop() instead"
onclick
propertySuppose you added your click event inline, like this :
<button id="myButton" onclick="alert( test )">Married</button>
Then, you can remove the event like this :
$("#myButton").prop( onclick , null); // Removes onclick property if found
click
event listenersSuppose you added your click event by defining an event listener, like this :
$("button").on("click", function() { alert("clicked!"); });
... or like this:
$("button").click(function() { alert("clicked!"); });
Then, you can remove the event like this :
$("#myButton").off( click ); // Removes other events if found
If you re uncertain how your event has been added, you can combine both, like this :
$("#myButton").prop( onclick , null) // Removes onclick property if found
.off( click ); // Removes other events if found
if you are using jquery 1.7
$( html ).off( click );
else
$( html ).unbind( click );
It is very easy using removeAttr.
$(element).removeAttr("onclick");
After trying so hard with bind, unbind, on, off, click, attr, removeAttr, prop I made it work. So, I have the following scenario: In my html i have NOT attached any inline onclick handlers.
Then in my Javascript i used the following to add an inline onclick handler:
$(element).attr( onclick , myFunction() );
To remove this at a later point from Javascript I used the following:
$(element).prop( onclick ,null);
This is the way it worked for me to bind and unbind click events dinamically in Javascript. Remember NOT to insert any inline onclick handler in your elements.
What if onclick event is not directly on element, but from parent element? This should work:
$(".noclick").attr( onclick , ).unbind( click );
$(".noclick").click(function(e){
e.preventDefault();
e.stopPropagation();
return false;
});
Try this if you unbind the onclick event by ID Then use:
$( #youLinkID ).attr( onclick , ).unbind( click );
Try this if you unbind the onclick event by Class Then use:
$( .className ).attr( onclick , ).unbind( click );
I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....
I have a div <div id="masterdiv"> which has several child <div>s. Example: <div id="masterdiv"> <div id="childdiv1" /> <div id="childdiv2" /> <div id="...
I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...
<form><input type="file" name="first" onchange="jsFunction(2);"> <input type="file" name="second" onchange="jsFunction(3);"</form> Possible to pass just numbers to the js ...
So I ve got a menu with a hover/selected state and it loads fine in IE6/IE7. However when I scroll down the page and put the element outside of the viewport and then back in I get a broken image! I ...
I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!