jquery - How do I prevent the JS onclick event in hyperlinks that are loaded in dynamically from firing? -


How do I stop the JS onclick event in hyperlinks that are loaded with firing dynamically? Instead of opening a separate window, I want to open all the links in a particular device on the same page. Here is the code that I tried when I click on a link from the loaded content, it opens in a new window. I think this issue has been made in the "onclick" feature in the tag, how can I neutralize it so that all the links open in a single device?

  $ (document) .on ('click', 'a', function)] {event.preventDefault (); // url // URL looks like this: & lt ; A onclick = "goToLink (this); returnback;" onfocus = onlink (this) href = "... linkAppearsHere" target = _self> course  var thisURL = $ (this) .attr ('href') + '#onetIDListForm'; var thisTitle = $ (this) .html (); $ ('# itempage') Load (thisURL); $ ('# itempageheading') .HTML (thisTitle) ;});  

The link should open by default in the current browser window. You can remove onclick and any target attributes:

  $ (document) .ready (function () {$ ('a'). RemoveAttr ('onclick'). RemoveAttr (' Target ');});  

event.preventDefault (); With your click handler is actually another click handler, so the click event is being processed on your handler as well as on the specialty. You can try to override the forum GoToLink so that nothing happens, or remove the onclick attributes on the elements.

To explain a bit further, you can have many click handlers if you open your console and do the following:

  var links = $ ('a' ); (Var i = 0; i & lt; 10; i ++) {links.on ('click', function) {warning ('click');}); }  

You will see 10 alerts for each click. You can remove click handlers like this:

  links.off ('click');  

However, it will not remove the onclick attribute that is embedded in the DOM. To do this, you will need to call the 'onclic' call


Comments