Change page title with jQuery
I just had a need to change the title of the page with JavaScript, and since I use jQuery I imediatelly wrote this:
$( 'title' ).html ( 'new title' );
and it didn’t work. Ok, how about this:
$( 'title' ).val ( 'new title' );
nope. So after some googling I found out that jQuery just can’t do that. You have to use plain old JavaScript:
document.title = 'new title';
I posted this because I think it’s interesting how one gets to rely on a tool he uses, without even thinking to use the technology on which the tool is build, even if that is clearly the better way to go. Or maybe you just get scared of working with the DOM directly if you use jQuery (or something alike) for some time. Don’t get me wrong, DOM is horrid to work with without some abstraction, but sometimes it works beautifully. But jQuery is working really hard to hide the DOM away from you thus subtly seeding fear into your mind.
it’s no coincidence I always think of Doom when I deal with DOM

Comments
Comment from skarab
Time December 16, 2009 at 11:10 pm
… use -> $(document).attr(’title’, ‘new title’);
Comment from Mark Kadlec
Time October 26, 2009 at 9:15 pm
I agree, and I keep thinking back to how I coded before being able to check the web or intellisense! Relying on these things have made me soft. :)