Posts Tagged ‘jquery’

Re-Ordering select list elements with jQuery

February 21st, 2011

So, I came across an interesting development problem.  I was embedding a ‘select’ list from a 3rd party web service, and I wanted to re-order the items shown.  More specifically, I wanted the most commonly selected elements to be at the top of the list.  Because I couldn’t access the raw HTML, directly changing the order was not an option.  jQuery to the rescue!  Here’s a small snippet I came up with that did just the trick:


Viola!  Way easy!

Book Review – jQuery in Action

April 9th, 2010

jQuery in ActionI just recently finished reading  jQuery in Action by Bear Bibeaut and Yehuda Katz.  I had used very little jQuery before reading it, and even less AJAX.  I can’t recommend this book highly enough.  Five Stars.  To be fair, I may be biased largely because jQuery is so awesome, anything about jQuery will inherit it’s awesomeness.  But either way, if you want to get into jQuery, this is a good place to start.

I’ve heard it pointed out that all of the information in this book is already online, on the jQuery website.  But that’s missing the point.  The book presents the information at a well-thought out pace and order, minimizing confusion.  For example, early on it spends a good amount of time introducing and explaining the various CSS3 selectors and getting your “Wrapped Set” of elements before it jumps into how to manipulate those elements.

The book process to move through all of the awesomeness that jQuery offers with DOM & Content manipulation, Event Handling, Animations, Plugins, and Finally AJAX.  My First attempt trying to implement AJAX was without a framework, using the WROX “Beginning AJAX” book.  I’ve decided that book isn’t worth it’s weight in lead, and that it should be pulled from the shelves.  jQuery makes it ridiculously easy to make POST and GET requests to the server, and handle the results.  I was using AJAX in production code within a week of reading this.

I don’t know what else to say.  The level of Awesome that jQuery exudes is matched only by other epic wins such as Dropbox and Vim.  If you haven’t tried jQuery, you need to. Now.

Buddypress jQuery is not defined error

December 16th, 2009

While developing a Buddypress plugin, I was running into a problem where none of my Javascript was working. Instead, Firebug was telling me: “jQuery is not defined”.  This was quite frustrating, as I could verify that the jQuery file was indeed, being loaded.  While a few other people received the same error for different reasons (corrupt files, etc.) I did not quickly find the solution for my problem.  Here it is:

Problem: Buddypress calls your plugin’s JS files BEFORE jQuery files.
This applies when you use the function wp_enqueue_script() – as you should.

Solution: Tell wp_enqueue_script your file depends on jQuery.
It turns out, wp_enqueue_script() takes a few optional parameters – the third being an array of other js files yours is dependent on.

Here’s how the call looks after the change:

Viola!  Your js file is now loaded after jQuery and you’re good to go.