views:

26

answers:

1

Hey guys, another question. I'm trying to do some basic jQuery stuff for my final project. I'll be using it to modify my already existing site created in Dreamweaver a few months ago.

However, no matter how I source the framework, it just won't take regardless of whether I host my own copy or link to someone else's like Google's.

I'm including my jQuery function calls within my already existing .js file that includes some auto generated functions. I also tried creating a new .js specifically for my jQuery functions and still nothing.

I realize this is vague, but any tips? Do I need another framework for jQuery to work off of to make animations like

.fadeIn() or .slideDown()?

Thanks guys and gals!

A: 

Just jQuery will work for this, however you need to make sure you're calling the functions on document.ready, like this:

$(function() { //or $(document).ready(function() {
  $("#myID").fadeIn();
});

Generally speaking, you should wrap all your startup/binding code in a document.ready wrapper like above, you can stick whatever you need in that one wrapper.

If you have just $("#myID").fadeIn(); and it's not at the bottom of your body, then it's probably running before the element exists, so that selector doesn't actually find the element...so nothing to fade in. You can see this behavior by placing this wherever your code currently is:

alert("#myID count: " + $("#myID").length); //probably alerts 0 currently

If this isn't the issue...check your console for javascript errors :)

Nick Craver
Sorry, I'm new to jQuery. So, I need to include document.ready within my html file at the bottom of the body for any function to work within my .js file?
JoeOzz
@Joe - You have 2 options, you can move the file to the end of body, **or** better, all you need to do is wrap your calls in the `document.ready` in your external file, then it doesn't matter where in the page it's included. So basically just wrap all your jQuery init code in a `$(function() { })` in that external file.
Nick Craver
Alright, so as long as I reference the correct div ids like this:$(document).ready(function() { $("#header").fadeIn();});I shouldn't have to include anything in my html file aside from linking my two .js files? This way I can just code away, referencing the divs I want to animate? Or, do I still need a simple document.ready in my html like I would using standard javascript with window.onload?
JoeOzz
@Joe - The first one's correct, just jQuery itself then your custom js files in the HTML, nothing else.
Nick Craver
I'm not sure now... still having issues. I linked to Google's jQuery hosting before my other js files and used the correct syntax within the document.ready at the top and still nothing. Could it be where I'm sourcing jQuery from or where I'm writing my code from (Expression Web 3)?
JoeOzz
Any idea how I would check my Javascript console for errors? I'm horribly new to coding. Is that a simple debugging option or term? I apologize for the frustration, haha!
JoeOzz
@Joe - In Chrome, right click, inspect element anywhere, console, or open firebug if you're using firefox...do you have the page in a place that I can take a look?
Nick Craver
I'll try to get it live as soon as possible. Thanks for the help, Nick!
JoeOzz
Just so you know, I abandoned jQuery for the time being and I'm currently trying Scriptaculous. Having the same issues... I'm following syntax and sourcing to the letter and getting nothing.
JoeOzz
Okay, it's live. Would there be a way I could send this link to you outside of this site?
JoeOzz
@Joe n.r.craver at gmail
Nick Craver
@Joe - The site doesn't have jQuery included...and the prototype/scriptaculous files are 404, looks like they didn't get uploaded.
Nick Craver
Yeah, I got too frustrated and removed them, but I could easily upload jQuery again. I'll take a look at that.
JoeOzz
That's weird, the permissions I set in my WinSCP should be fine. I might be delirious from not getting anything done in nearly 8 hours on this project, but it is 644 for files and 755 for directories. Right?
JoeOzz