jQueryWhat is jQuery?• jQuery is a JavaScript Framework• jQuery takes away the pain• jQuery is a designers best friend• jQuery is designed to change the way that you write JavaScript.jQuery Simplifies• CSS Selectors$(“a”).css(“color”,”red”);• Chainable$(“a”).css(“background-color”,”green”).click(function(){ return confirm(“Are you sure?”);});• Web 2.0 Effects• Easily Extensible• Enhanced Browser Support. Separation• CSS - Presentation from markup.• jQuery - Behavior from markup.• *Degradation* (but do so gracefully)• No more <a onclick=”doSomething()” href=” ...• Cleaner, Easier to manage codeWhy I love it• Immediately productive• Excellent documentation http://docs.jquery.com• Simple SyntaxPrototype: new Ajax.Updater('placeholder', url, { method: 'get', parameters: par });jQuery: $('#placeholder').load(url + par);• Active Community• Less is MoreDemo: Ratinghttp://kylebradshaw.com/presentations/jQuery/rating.phpTips• Speed + Efficiency (jrules.js)http://somedirection.com/2008/03/14/structuring-jquery-for-speed-and-efficiency/• <body id=”home”>• if ($("body#home").size()) { // only applies rules on the homepage}Tips• Start building the degraded version FIRST• Turn off JavaScript while testing• Leverage Plugins• Utilize <noscript>• Inline JS isn’t necessaryDemo: Comments• Toggle-able Items? - Degrade Show/Hide with CSS.toggle_me (display:none;)Enhance with jQuery$(".toggle_me").show();$(".hide_me").hide();• Ex. Comment Formhttp://kylebradshaw.com/presentations/jQuery/comments.php Avoid• Never use jQuery inlinethese practices do not degrade with JS turned OFF • http://reboot.com<a id="showAndHideComments" href="javascript:toggleVisibility('toggle');">• http://rightsagent.com<img onclick="return ra.popups.showPopup('register', 'txtNewUserEmail');" style="cursor: pointer;" src="/media/images/Register.gif"/>• Building HTML in JavaScript• Ignoring Degradation - “With great power comes great responsibility”
Add New Comment