0

I am writing a script for my client that already has some encrypted JavaScript. Somewhere in encrypted JavaScript there is .remove() event that trigger with a particular button. I found a script jQuery - Trigger event when an element is removed from the DOM that detect the .remove() event. After that i tried to block that event with this:

$('#fileElem').on('destroyed', function(){
    $('#fileElem').die('remove');                            
    $('input[name="done_upload"]').trigger('click');
});

But i got Uncaught TypeError: Object [object Object] has no method 'die' might be the destroyed event trigger after .remove() action, I am not sure. And as i used to auto trigger the button with $('input[name="done_upload"]').trigger('click'); not working because i got error before trigger event.

Can anyone help me to stop removing DOM element?

Community
  • 1
  • 1
jogesh_pi
  • 9,762
  • 4
  • 37
  • 65

2 Answers2

4

.die() is filed under the removed section of jQuery, so unless if you are using an older version of jQuery (like <1.8), it doesn't exist anymore. That's what's causing that thrown error.

This fiddle (loaded with 1.9) alerts false while testing for .die(), which means it does not exist. If you use 1.8.3 or earlier though, it will alert true which means it's still there.

If you want to prevent the removal of that element, I suggest you "hijack" (replace) the button's click handler instead.

Joseph
  • 117,725
  • 30
  • 181
  • 234
  • 1
    It's probably worth mentioning that he can refer to the element as `$(this)` inside the event handler, as it may no longer be accessible via DOM parsing (unlikely, I know, but worth him knowing). – Reinstate Monica Cellio Oct 30 '13 at 12:19
  • @Archer but a jQuery object, regardless if it has fetched anything on the DOM, will still have it's prototype functions. Doing `$('#foo').remove().die().off()` with no `#foo` existing will not throw an error. – Joseph Oct 30 '13 at 12:25
  • 1
    Yeah, but it may not return anything is my point, whereas `this` will still be a reference to the object. Like I said, it's unlikely, but there's really no harm in explaining the use of `this` to the OP. – Reinstate Monica Cellio Oct 30 '13 at 12:27
2

I think that destroyed event is fired when element is already destroyed so you get an empty jQuery query result.

shanabus
  • 12,989
  • 6
  • 52
  • 78
Romko
  • 1,808
  • 21
  • 27