tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

Function jQuery $

One of the important concepts in jQuery is a call to '$'.

'$' Is a pseudonym for the space 'jQuery'.

Few simple examples of using jQuery

Examples

Example 1

jQuery provides a function that removes extra spaces from a string
str = "    foo     ";
jQuery.trim(str); // returns "foo"
The output of the code above will be:

Example 1a

jQuery provides a function that removes extra spaces from a string: shortest way
str = "    foo     ";
$.trim(str); // returns "foo"
The output of the code above will be:
This example is similar to the previous one. Use '$' instead of 'jQuery' is a simpler and shorter way to refer to objects with the jQuery library

Example 2

The following function adds a class called bar for all paragraphs (p) that have a class named foo
$("p.foo").addClass("bar");
The output of the code above will be:

Example 3

In the following example function with name 'myfunc' is executed immediately after loading the page:
$(document).ready(function() {
    myfunc();
});

Example 4

In the following example for each even row is added class name oddStripe, and for the odd rows - class name evenStripe
$(document).ready(function() {
  // Stripe all the tables in the document using the 
oddStripe and evenStripe CSS classes.
$('tr:odd').addClass("oddStripe"); $('tr:even').addClass("evenStripe"); });
The output of the code above will be:
Was this information helpful?
   

Comments