HTML/CSS Service

jQuery FUNCTIONS

Category: Learn jQuery    |    1,145 views    |    1 Comment  |   

 

CALLBACKS AND FUNCTIONS

A callback is a function that is passed as an argument to another function and is executed after its parent function has completed. The special thing about a callback is that functions that appear after the “parent” can execute before the callback executes.

Another important thing to know is how to properly pass the callback. This is where I have often forgotten the proper syntax.

Callback without arguments

For a callback with no arguments you pass it like this:

 $.get('myhtmlpage.html', myCallBack);

Note that the second parameter here is simply the function name (but not as a string and without parentheses). Functions in Javascript are ‘First class citizens’ and so can be passed around like variable references and executed at a later time.

Read more…

Share/Save/Bookmark

  • No Related Post

 

Adding and Removing a CSS Class with jQuery

Category: Learn jQuery    |    6,083 views    |    2 Comments  |   

irst, add some style information into the <head> of your document, like this:

 <style type="text/css">
    a.test { font-weight: bold; }
 </style>

Next, add the addClass call to your script:

  $("a").addClass("test");

All your a elements will now be bold.

To remove the class, use removeClass

 $("a").removeClass("test");
  • (CSS allows multiple classes to be added to an element.)
[edit]

Special Effects

In jQuery, a couple of handy effects are provided, to really make your web site stand out. To put this to the test, change the click that you added earlier to this:

 $("a").click(function(event){
   event.preventDefault();
   $(this).hide("slow");
 });

Now, if you click any link, it should make itself slowly disappear.

Share/Save/Bookmark

 

How jQuery Works

Category: Learn jQuery    |    2,855 views    |    Add a Comment  |   

 

THE BASICS

This is a basic tutorial, designed to help you get started using jQuery. If you don’t have a test page setup yet, start by creating a new HTML page with the following contents:

 

<html>

 

  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      // Your code goes here
    </script>
  </head>
  <body>
    <a href="http://jquery.com/">jQuery</a>
  </body>
  </html>

Edit the src attribute in the script tag to point to your copy of jquery.js. For example, if jquery.js is in the same directory as your HTML file, you can use:

 <script type="text/javascript" src="jquery.js"></script>

You can download your own copy of jQuery from the Downloading jQuery page.

Launching Code on Document Ready

 

The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this: Read more…

Share/Save/Bookmark