How we got here From Java Script to jQuery

JavaScript, originally named LiveScript, was invented by Netscape's developers in the early 90s. By 1996, Netscape had renamed LiveScript to JavaScript in order to boost its popularity by linking it to Java (developed separately by Sun Microsystems). Java, which had been around a few years itself already, was becoming even more popular because people were starting to run it in websites by using a separate plugin called an "applet". There are some ways in which Netscape's developers took care to make JavaScript syntax and functions very similar to Java, but there are differences of course. The biggest difference is that JavaScript is a client-side scripting language that is interpreted, which means it runs live in the browser and is not pre-compiled the way Java is in order to execute and run.

It's a bit complicated and beyond the scope of this book to explain it all, but of course, Microsoft's browser, Internet Explorer, in competition with Netscape, took a completely different route and released IE with the ability to run Microsoft's own VBScript. VBScript was made to look and work similar to VisualBasic, but again as an interpreted language, instead of a compiled one like VB. When JavaScript seemed to be gaining more popularity with budding web developers than VBScript, Microsoft introduced JScript. JScript was crafted to be very similar to JavaScript, in order to appeal to JavaScript developers without any licensing hassles for Microsoft, but there were still quite a few differences. You could however, if you were very careful and didn't have high expectations, write a script that executed as JavaScript in Netscape and JScript in IE 3.0.

Yes. What a pain! To this day, IE still only executes VBScript and JScript! The difference is, both Microsoft and Mozilla (Netscape's creation foundation) submitted JavaScript and JScript to ECMA International, an organization which focuses on creating and maintaining standards for information communication systems. In addition to JavaScript, you can thank ECMA Int. for standards running the gamut from CD-ROM and DVD formatting specs to the newer Open XML standards used in Office suites like MSOffice and OpenOffice.

It has taken well over ten years from JavaScript's initial submission in 1997. But as of 2010, both JavaScript and JScript standards are very similar, and both are now technically named ECMAScript (but who wants to try and say that all the time?).

Many developers who came of age in the later 90s and early 2000 use the terms JScript and JavaScript interchangeably without realizing there's a difference! And yet, there are still differences. IE handles ECMAScript in some ways differently compared to Firefox and other browsers. For clarity and sanity, this title will continue to call ECMAScript JavaScript.

Once upon a time, there was JavaScript

Back in the "dark ages", that is before jQuery came along in early 2006, in order to create a more dynamic page that responded to events or manipulated the DOM using JavaScript, you had to spend a lot of time writing long and often clumsy JavaScript using while and foreach loops, with perhaps a few or many if/else statements squashed inside those loops.

If you wanted to evoke your JavaScript immediately, it had to be placed in the header tags or in the body with an onload event handler. The problem is that this method waits for the entire page and all its content to load, including things such as CSS files and images. If you created a loop to select and manipulate a set of elements, and wanted to perform an additional change to that set of elements, you had to select them again in an additional loop or have a long loop with if/else statements that could become complicated to track and maintain.

Lastly, many events you might want the page to respond to, often had to be called separately. I recall sometimes having to create an event script for Firefox (or way, way back in time, on Netscape) and a separate event script for IE. Occasionally, I'd even devise little creative ways to detect different browsers or "trick" them into responding to different events that on the whole were just to make the page appear to look and respond somewhat similarly between the two browsers.

As much as I was enjoying programming and adding engaging interactivity to my sites, I was often a little less than enthused to embark on an in-depth JavaScript endeavor.

Why jQuery is simpler than JavaScript

All that ended with jQuery. jQuery does not stand alone, meaning it's not a new language that browsers support. It essentially boils down to just creating better JavaScript that works. As mentioned, it's a JavaScript library that gives you simpler, easier-to-construct syntax to work with. That jQuery syntax gets interpreted by the browser's JavaScript engine as plain JavaScript. jQuery simply hides a lot of the "ugly" and complicated things that you used to have to do yourself with JavaScript and does them for you.

One of the first things that I grew to love about jQuery (other than its excellent, clear documentation) is that it is essentially a fantastic "loop engine". Now, I call it "looping", but those of you with a more formal programming background or some previous experience with jQuery have probably heard the term used as: implicit iteration. Essentially, jQuery iterates, that is, repeats (aka: loops) through the selected elements of its container object without the introduction of an explicit iterator object, hence, using the term implicit. OK, complicated definitions aside, it simply means you can do just about anything you need to a set of elements, without ever having to write a foreach or while loop! Most people I chat with about jQuery, have no idea this is what jQuery is really doing under the hood.

What's even cooler than being able to easily loop through selected elements is the ability to select them in the first place using standard CSS notation. Then, as if those two features weren't wonderful enough, once you've grabbed a set of elements, if you have more than one operation that you want to apply to the selected set of elements, no problem! Rather than evoking individual functions and scripts on the selection over and over, you can perform multiple operations all at once, in a single line of code. This is called statement chaining. Statement chaining is awesome and we'll learn all about it and take advantage of it often throughout this title.

Lastly, jQuery is extremely flexible and most importantly, extensible. In the four years it's been around, there have been thousands of third-party plugins written for it. It's also very easy to write your own jQuery plugins as we'll discover in this book. However, you'll probably find that for most of your more practical day-to-day WordPress development and maintenance needs, you won't have to! Just as WordPress saves you loads of time and work, you'll find with jQuery that a lot of the work has already been done as well.

Whatever you wish to create, you can probably find a way to do it fairly easily with a jQuery plugin and a tweak or two to your WordPress theme. Perhaps you might just need to write a quick and simple jQuery script to enhance one of your favorite WordPress plugins. We'll go over the basics of jQuery and the most common uses of applying it to WordPress in this book and you'll quickly see that the possibilities are endless.

Getting to know jQuery

This book is here to help you create solutions for scenarios and problems that tend to confront WordPress users. I'm hoping to help you save a little time having to poke through WordPress' wonderful yet extensive codex and jQuery's API documentation. But by no means will this book replace those resources or the great resources maintained by jQuery and WordPress' community members.

For jQuery, I highly recommend you check out jQuery's documentation and the Learning jQuery site:

Was this article helpful?

0 0
Blogging Bounty

Blogging Bounty

Finally Learn How To Use Your Blog As A Cash Machine And Stop Wasting Your Time! This Book Is One Of The Most Valuable Resources In The World When It Comes To The Network Marketers Guide To Leads Through Blogs!

Get My Free Ebook

Post a comment