Learning jQuery - Fourth Edition by Jonathan Chaffer & Karl Swedberg
Author:Jonathan Chaffer & Karl Swedberg
Language: eng
Format: azw3, epub
ISBN: 9781782163145
Publisher: Packt Publishing
Published: 2013-06-24T21:00:00+00:00
Tip
The jQuery.fn object is an alias to jQuery.prototype, provided for conciseness.
We can then call this new method from our code after using any selector expression:
$('div').myMethod();
Our alert is displayed (once for each <div> in the document) when we invoke the method. We might as well have written a global function, though, as we haven't used the matched DOM nodes in any way. A reasonable method implementation acts on its context.
Object method context
Within any plugin method, the keyword this is set to the current jQuery object. Therefore, we can call any built-in jQuery method on this or extract its DOM nodes and work on them. To examine what we can do with object context, we'll write a small plugin to manipulate the classes on the matched elements.
Our new method will take two class names and swap which class is applied to each element with every invocation. While jQuery UI has a robust .switchClass() method that even permits animating the class change, we'll provide a simple implementation for demonstration purposes:
// Unfinished code (function($) { $.fn.swapClass = function(class1, class2) { if (this.hasClass(class1)) { this.removeClass(class1).addClass(class2); } else if (this.hasClass(class2)) { this.removeClass(class2).addClass(class1); } }; })(jQuery); $(document).ready(function() { $('table').click(function() { $('tr').swapClass('one', 'two'); }); });
Download
Learning jQuery - Fourth Edition by Jonathan Chaffer & Karl Swedberg.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
ActiveX | ASP.NET |
Cold Fusion | CSS |
DHTML | Java Server Pages |
JavaScript | PHP |
Python | Ruby |
XSL |
Hello! Python by Anthony Briggs(9916)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Svelte with Test-Driven Development by Daniel Irvine(7166)
Test-Driven Development with PHP 8 by Rainier Sarabia(6892)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6762)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6414)
Web Development with Django by Ben Shaw Saurabh Badhwar(6226)
React Application Architecture for Production by Alan Alickovic(5949)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
Kotlin in Action by Dmitry Jemerov(5063)
Audition by Ryu Murakami(4583)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4453)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4317)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4300)
Functional Programming in JavaScript by Mantyla Dan(4038)
