Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jquery help Re: jquery help

#107719

In order for what you want to accomplish, you will need to follow what TheDoc has written.

From what you have shown us though, it looks like you could use a quick tip on JavaScript methods.

jQuery uses what is called method chaining. This is what allows you to do stuff like:

$('#some-id').find('.some-class').fadeOut();

The above code snippet gets the element that has the id some-id, finds each of it’s children elements with a class of some-class and fades them out.

You can think of a method as a fancy name for a function. Methods are usually part of what is known as object oriented programming (OOP for short).

A method inside of JavaScript might look something along the lines of:


var myHelpers = {
findElement: function(elm) {
// Some code here
}
};

// or maybe like this
myHelpers.findElement = function(elm) {
// Some code here
};

There are many ways to accomplish methods in JavaScript.
In the above code snipped, myHelpers is an object, and findElement is a method of myHelpers.

So with that, you should know, fadeIn, delay, and fadeOut are all methods of the jQuery object.

In the code you provided, you have the following:


$('.sent-message').delay(4000).fadeOut("slow").('intro, form#contact_form').show();

When you hit that single dot, the browser will want a method name, but none is provided, so there an error occurs. A method call Always needs a method name. So always remember that when you see code like jQuery.

Now, what TheDoc has provided within the fadeOut method is known as a callback function. They are special in that they usually execute immediately following the successful (and sometimes unsuccessful ) execution of the initial method call; in this case fadeOut.

I hope I have helped you in any way. If I have offended you in any way, I am truly sorry.

If you find your self wanting to learn more JavaScript or jQuery, Code Academy is a great place to start. http://www.codecademy.com/learn

-Mike