I’m creating a bookmarklet and everything was going ok. I had a function that loads jQuery asynchronous if the page didn’t have it and then load my script or load my script directly if the page had jQuery.
Then I try to use the delegate function which is only available in jQuery 1.4.something. I can check the jQuery version with $().jquery but then if i load jQuery i have jQuery twice and events executes twice.
Is there a way to remove the previous loaded jQuery and then load the new version that I need?
There is, but you’ll be breaking the page when you do so, so I highly recommend not doing this. To remove jQuery itself:
This is just to show it can be done (though it doesn’t remove all the effects it had), in your case I would not do this, what you’re doing will really break the webpage your bookmarklet’s running on.
Instead, consider if your bookmarklet needs the latest jQuery API, would a version behind fit all your needs? If so then use that, even if it’s a bit less efficient, so it works whether the page has a slightly older version or not.