jQuery Notes


References

Include jQuery in our code

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

Basics

Selectors

Select a tags:

$("a");

Select the class named gorp:

$(".gorp")

Select the id named fmep:

$("#fmep")

Select all as inside li tags

$("li a")

Ways to style an element

Style inline:

$("#fmep").css("border", "2px solid black")

Style with a JS object:

var styles = {
   backgroundColor: blue;
   margin: 10px auto;
}

$("#fmep").css(style);

Methods

Common and useful methods:

.text() - can be used to get or set the text content in an element
.html() - get or set HTML content in an element
.attr() - get or set an attribute of an element like src in an img tag
.var() - get or setthe value from a form, select ... element
.addClass() - add css class
.removeClass() - remove css class
.toggleClass() - toggle a css class
THIS INFORMATION IS PROVIDED UNDER A GPLV2 LICENSE
THE GPLV2 LICENSE CAN BE VIEWED HERE