Reputation: 4971
I am developing a widget to implement a "Zopim" like live chat. To modify the DOM of the page my widget will live in I'd like to use jQuery, but I want to do that without polluting the global namespace of the host page.
How can I achieve that?
Upvotes: 0
Views: 110
Reputation: 171690
Steps
Check if window.jQuery
is defined. If it is and matches version you need (jQuery.fn.jquery
) use that version.
Otherwise Load jQuery and use noConflict(true)
to assign to another variable and maintain any existing $
in page
Upvotes: 1
Reputation: 5126
Use jQuery.noConflict(true)
jQuery.noConflict(true) will remove all jQuery variables form global scope.
https://api.jquery.com/jquery.noconflict/
Upvotes: 1