• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Falling in love with jQuery?

 
Scott Selikoff
author
Saloon Keeper
Posts: 3887
15
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the book website, it says "You'll fall in love with it when you see 20 lines of code reduced to three.". Could you give an example or two of this? The description sounds appealing but I'd like more substance. What can jQuery do that would be a huge pain to do without?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Event handling, Ajax, DOM manipulation and effects come immediately to mind. Especially when you factor in cross-browser issues.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, here's an example I like to use. Following is some typical code to make an Ajax request, sending the value of a form field as a parameter, and shove the response text into a DOM element:


Here's the equivalent code using jQuery:


And this is a fair comparison. Both code examples work across multiple browsers that support Ajax, and both properly encode the request body.

The jQuery code actually performs some error-checking and event handling that the raw JavaScript example doesn't do.

 
Scott Selikoff
author
Saloon Keeper
Posts: 3887
15
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, that is actually the kind of comparison that's really useful.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic