javascript - Facebook SDK takes over "$" from jQuery - how to stop that? -
i'm using both facebook sdk , jquery... reason, facebook sdk loading, $
no longer works jquery object. jquery calls still work have use jquery
instead of $
... see below example. have other code in footer jquery stuff , $
doesn't work there either. everything functions hate , want able use $
shortcut jquery! how can $
back?
<script type='text/javascript' src='http://x.com/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script> <script> window.fbasyncinit = function () { fb.init({ // (this code straight fb developer docs) appid: '1234123412341234', channelurl: '//mysite.com/channel.html', status: true, cookie: true, xfbml: true }); function checkloginstatus(response) { if(response && response.status == 'connected') { jquery('#login-btn').hide(); jquery('#logout-btn').show(); console.log('user id: ' + response.authresponse.userid); } else { jquery('#login-btn').show(); jquery('#logout-btn').hide(); } } // load sdk asynchronously (this code straight fb developer docs) (function (d) { var js, id = 'facebook-jssdk', ref = d.getelementsbytagname('script')[0]; if (d.getelementbyid(id)) { return; } js = d.createelement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_us/all.js"; ref.parentnode.insertbefore(js, ref); }(document)); </script>
just use self-executing function, , pass jquery
argument $
.
jquery.noconflict(); (function ($) { fb.init({ // (this code straight fb developer docs) appid: '1234123412341234', channelurl: '//mysite.com/channel.html', status: true, cookie: true, xfbml: true }); function checkloginstatus(response) { if(response && response.status == 'connected') { $('#login-btn').hide(); $('#logout-btn').show(); console.log('user id: ' + response.authresponse.userid); } else { $('#login-btn').show(); $('#logout-btn').hide(); } } })(jquery);
you can read more here
Comments
Post a Comment