Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, July 13, 2016

How to remove

How to remove "onclick" with JQuery?


php code:

Qualify  

How to remove onclick="check($id,1) so "Qualify" can not be clicked or "check($id,1) won't be fired. How to do it with JQuery?

Answer by GhiOm for How to remove "onclick" 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');
      Qualify

Answer by acme for How to remove "onclick" with JQuery?


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"

Answer by Vishnu Sharma for How to remove "onclick" with JQuery?


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');  

Answer by bboydflo for How to remove "onclick" with JQuery?


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.

Answer by Jaydeep Jadav for How to remove "onclick" with JQuery?


if you are using jquery 1.7

$('html').off('click');  

else

$('html').unbind('click');  

Answer by Milan for How to remove "onclick" with JQuery?


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;  });  

Answer by Nor Leyva Lpez for How to remove "onclick" with JQuery?


It is very easy using removeAttr.

$(element).removeAttr("onclick");  

Answer by John Slegers for How to remove "onclick" with JQuery?


Removing onclick property

Suppose you added your click event inline, like this :

  

Then, you can remove the event like this :

$("#myButton").prop('onclick', null); // Removes 'onclick' property if found  

Removing click event listeners

Suppose 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  

Removing both

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  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.