At the Forge - jQuery
What makes jQuery so special and different? What does it offer? And, how can you integrate it into your applications? This month, I try to answer all of these questions, as we explore some of the basic features of jQuery. Next month, we'll look at some of the UI widgets that jQuery provides to spruce up our sites and make them more functional.
$('foo') // Prototype
to get the elements with id attributes of foo and bar. The number of parameters to Prototype's $() determines whether it returns a single value or an array, as well as how many elements that returned array contains.
Prototype also lets you retrieve items using CSS selectors (and a variety of pseudo-selectors), using the $$() function. For example:
$$('tr.even') // Prototype
returns an array (and always an array, even if it matches only a single object) of all of the tr tags with a class of even.
Well, jQuery works similarly, except that it has only a single function, $(). That function is smart enough to recognize what you want, based on a single CSS-style selector that you give it. (And yes, you may specify only a single selector.) However, id attributes need to begin with a # character, as is the case in CSS. Thus, you can say:
$('#foo') // jQuery
to get all the tags (and there should be only one such tag) that have an id attribute of foo, and:
$('tr.even') // jQuery
Web Development News
- Readers' Choice Awards--Nominate Your Apps & Gadgets Now!
- Memory Ordering in Modern Microprocessors, Part I
- Source Code Scanners for Better Code
- diff -u: What's New in Kernel Development
- RSS Feeds
- Non-Linux FOSS: AutoHotkey
- Using Django and MongoDB to Build a Blog
- Tech Tip: Really Simple HTTP Server with Python
- Security Hardening with Ansible