One aspect of jQuery that I’ve really come to appreciate is its ability to apply filters to elements on a Web page. Let’s say, for example, that you want to disable all of the links on a Web page if the user has not yet logged in.
In most server-side frameworks, this requires you to add conditional logic to every link on the page (or just use a different template entirely). In PHP, you’d have to do something like:
<?php if ($login_page) { ?>
My stuff
<?php } else { ?>
<a href="">My stuff</a>
<?php } ?>
You could perhaps shorten that a bit if you were clever, but that’s what you’re up against. And the problem is that you have to repeat it 100 times if you have 100 links on the page. You have to add a lot of code to your page to do something relatively simple.
On the other hand, with a tool like jQuery, you can accomplish something similar with one line of code.
$("a").bind("click", function(e) { return false; });
Needless to say, it’s a much cleaner and simpler approach. This approach won’t work in terms of security since users can just disable JavaScript, but it’s great in terms of clarity and simplicity.
What I’m wondering is why more server-side frameworks don’t have similar selector-based DOM manipulation tools built in. Wouldn’t it be cool if you could attach such filters to views on the server side and manipulate the output page before it’s presented? Why isn’t this more common?
Flush Michele Bachmann
Michele Bachmann, a first term Congresswoman from Minnesota, is perhaps the stupidest person in the United States House of Representatives (and that’s saying a lot). I already knew she was an idiot, but the performance she turned in on Hardball today confirms that she really has no business serving in government. (Hilzoy has the details.)
I donated $25 to her opponent, Elwyn Tinklenberg, and I’d recommend others do so as well.