4

I am trying to execute a simple bit of jQuery or JavaScript once logged in to my Facebook account. The end goal at this moment is to click on my custom feed once the element is visible, rather than having it default to the entire Facebook friend feed.

On trying to code this using my Developer's Console in Chrome no JavaScript/jQuery seems to work at all. Even just a simple $('div'); returns null. Is it possible to run code on Facebook's page? What are they doing differently?

I guess the end goal would be to click a div if the .val('give a waffle'); but just understanding why it has not worked until now would also be interesting.

Any hints, tips or suggestions are more than welcome.

4
  • 2
    um....whats the purpose of this? Commented Feb 7, 2012 at 21:31
  • Are you developing a FB app? If so the apps are contained in an iFrame and you can use whatever you like - jQuery, JavaScript, whatever. I've done some FB development and have had no problems using their APIs as well as jQuery to achieve whatever I needed. However, in your case I don't know enough about what you're doing to know if it is even referring to an FB app or if you're trying to paste jQuery snippets into form elements in your profile... In short, can you clarify in your question? Maybe being more specific might give some insight into how to help you. Commented Feb 7, 2012 at 21:33
  • of course you can execute js in the console window of your browser while on facebook. Commented Feb 7, 2012 at 21:34
  • Hi, Thanks for taking your time to answer my question. I am just playing with my own version of Facebook to be honest. I have set up a custom news feed, consisting of friends i wish to hear about, and constantly have to click on that to view it and i'd like that to be the default. Therefore I just want "on Facebook.com load > click CustomNewsFeed button" so that I can skip the entire newsfeed and basically filter out the rubbish.. Commented Feb 8, 2012 at 22:34

1 Answer 1

12

Facebook doesn't use jQuery, if you want to play with their page using jQuery commands you'll need to load it. Just copy the contents of http://code.jquery.com/jquery-1.7.1.min.js and paste it into your console first. Then proceed as usual.

Additionally you could let Google host your jQuery :

<script type="text/javascript"
 src="//code.jquery.com/jquery-2.2.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    // This is more like it!
  });
</script>

Many sites do this so the chances of your user already having the library cached is relatively high.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Sinetheta. Worked like a charm
Updated the jquery-from-cdn link. Although I would probably suggest that if someone wanted to "play around" with the DOM on a random site they take a look at the modern Chrome console api developer.chrome.com/devtools/docs/commandline-api With tools like $ (still not jquery, but closer) there isn't much need to pull in jquery itself just to find or manipulate elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.