jQuery - things I've learned so far
Ok so most of this is agreeably very, very basic.
But I gotta start somewhere... and writing it down - which at this point in my discoverizations might not mean anything to anyone and is probably way behind the general knowledge of anybody bothering to read a post about jQuery - helps me retain the basic points. So...
// Loading the functions
All the tutorials and examples I've looked at so far initialize the jQuery functions on any given page by first linking to the javascript (like you would for any js)
<script src="jquery.js"></script>
and then, rather than a window.onload or body onload command, the syntax is very simply this
<script type="text/javascript">
$(document).ready(function(){
//All the functions go here
});
</script>
The way I understand it so far, this causes the scripts to 'start' as soon as the DOM is loaded (i.e. the browser loads the full html structure of the page) but without waiting for images or other large assets to load completely. They say this is much faster and cleaner, and from what I have seen so far, I believe it!
// CSS-like designations
For this I am grateful ... jQuery uses regular ol' css designations to select various elements on the page.
For example, in that table striping tutorial (see previous post), the designation for a row in the table is like this:
$(".stripeMe tr")
where the class of the table is "stripeMe" ... hey, I get this part right away!
// Basic jQuery code format (from that same table striping tut)
- jQuery code starts with $
- Followed by parenthesis
- Inside parenthesis is what you tell jQuery to find - don't forget the quotes
- $('p') = find all paragraphs
- $('.whatever') = find everything with class="whatever"
- $('.stripeMe tr') = find all tr (table rows) inside an element with the "stripeMe" class (ala the example above)
// Custom selectors
Down towards the bottom of this page, the custom selectors list includes nifty super-simple things like :even, :odd, :first, :last, :hidden, :visible... so easy! For example, in the table striping tutorial, what I've otherwise seen as fairly complex custom javascript solutions to select every other row of a table can simply be replaced by tr:even ... how easy is that?!?


There are no comments for this entry.
Add Comment