question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vanilla JS method breaks if jQuery is included

See original GitHub issue

I’m developing a website in Wordpress where I use just vanilla JavaScript and no other frameworks, so while using Velocity I use function Velocity(...). While testing I need to activate the Debug Bar which relies on jQuery, but when doing it, Velocity is looking for jQuery method instead giving the error ReferenceError: Can't find variable: Velocity. How can I resolve this issue? Sincerely, I don’t want to modify all the Velocity(...) functions with jQuery callback and then modify them again when testing is done. Hope there’s a solution for this.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
Rycochetcommented, Nov 23, 2016

Currently Velocity says “Oh, here’s jQuery, let’s connect to that instead” (same for Zepto) - so it can’t do both, you need to add a line (after loading Velocity) to copy it over -

window.Velocity = window.Velocity || (window.jQuery || window.Zepto || window).Velocity;
2reactions
MattyBalaamcommented, Nov 23, 2016

Alternatively you can try what I do and use an IIFE

(function(window, document, velocity, undefined){

// all your your code here

}) (window, document, window.jQuery ? window.jQuery.Velocity : window.Velocity);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Checking if jquery is loaded using Javascript - Stack Overflow
If the $(document) ready function runs at all, then jquery is loaded. So you could simply do $(document).ready(function(){ alert("Ready!"); }); ...
Read more >
Subscribing to plugin events break vanilla javascript and jQuery
If I re-add the event listener, it starts working again. Example of event listener on my page: let myElement = document.getElementById('myButton ...
Read more >
The Basics of DOM Manipulation in Vanilla JavaScript (No ...
The first one is that we can't call Node methods on the result and propagate them to its elements (like you might be...
Read more >
How to do Everything jQuery can do with Vanilla JavaScript
It's time to come home to Vanilla JavaScript. These days there's nothing you can't do in jQuery that Vanilla JavaScript can't do just...
Read more >
You Might Not Need jQuery
Examples of how to do common event, element, ajax and utility operations with plain javascript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found