0

I'm trying to unbind an event from a specific element and upon research, I found this. Which is useful. In itself. I didn't know you could do that. But:

Is there a way to make it work in a browser/Chrome extension? I'm talking about content scripts.

The reason why this doesn't work the way it's described there is that the website which has attached the event in question with its own script is using a different jQuery object than the one in my extension's includes/ folder. And I can try to search the event via jQuery._data(el, 'click'); but that is my jQuery object, not the one of the website where the events are apparently stored. I'm glad I figured that out after hours of fiddling around.

Or maybe it is possible to access the website's jQuery object itself?

EDIT:

What I'm ultimately trying to achieve works in theory but … it's complicated. The original script uses a plugin event and keeps reinstalling it with .on('mouseleave',….

Anyway, this is what I got thanks to you, pdoherty926:

var $el = $('div.slideshow');
$('h2', $el).click(function(){  console.log('ouch!');  });  // test event
var $slides = $('.slides', $el).detach();
$copy = $el.clone(false);
$slides.prependTo($copy);
$el.replaceWith($copy);

The test event doesn't get triggered but the event I'm actually trying to remove still fires. I can imagine figuring it out, though, now that I got closer to my goal.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
WoodrowShigeru
  • 1,418
  • 1
  • 18
  • 25

1 Answers1

0

Okay, the aforementioned re-installation on mouseleave really messed up this otherwise satisfying suggestion. (The site is using the jQuery Timer plug-in by Cyntaxtech). So here's how I solved it instead: I simply changed the class name (-.-' )
Now the re-installation code cannot find the element anymore.

This is how my finished script looks like:

function stop_happening() {

  var $el = $('div.fullwall div.slideshow');

  $el
     // first, stop the current automation.
    .timer('stop')    // Timer plug-in

     // next, change class name in order to prevent the timer 
     // from being started again.
    .removeClass('slideshow').addClass('slideshow-disabled-automation');

   //--- copied some extra code from the website itself for the onclick 
   // events which are supposed to keep working. I wish I could do *that* 
   // programmatically but I'm glad I got as far as I got. ---//
   // […]        
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129