You need a way to toggle all of the checkmarks in a group of checkboxes. Each checkbox should be toggled independently of the others.
Write a .toggleCheck() plugin that works like the .toggle() and .toggleClass() methods in the jQuery core to allow you to set, clear, or toggle a checkbox or group of checkboxes:
This .toggleCheck() method is built on top of a more general-purpose .toggleAttr()
method that works for any attribute:
Why go to the trouble of building something so general-purpose? Now we can write similartogglers for other attributes with almost no effort. Suppose you need to do the same thing as .toggleCheck(), but now you’re enabling and disabling input controls.You can write a .toggleEnable() in one line of code:
Note how the onValueand offValueparameters let us swap the true and false attribute values, making it easy to talk about “enabling” the element instead of the less intuitive “disabling” that the disabled attribute provides normally.
As another example, suppose we need to toggle a foo attribute where its “on” state is the string value bar, and its “off” state is to remove the attribute. That’s another one-liner:
It’s always good to beware of feepingcreaturism (aka creeping featurism). If all we really needed were to toggle checkboxes, we could code the whole thing like this:
That is a bit simpler than our .toggleAttr() method, but it’s only useful for the checked attribute and nothing else. What would we do if we later needed that.toggleEnable() method? Duplicate the whole thing and change a few names?
The extra work in .toggleAttr() buys us a lot of flexibility: we now can write a whole family of attribute togglers as straight forward one-liners.
J Query Related Interview Questions
|HTML 4 Interview Questions||HTML Interview Questions|
|HTML 5 Interview Questions||Zend Interview Questions|
|JqueryUI Interview Questions||Dynamic HTML Interview Questions|
|XQuery Interview Questions||jQuery Mobile Interview Questions|
J Query Related Practice Tests
|HTML 4 Practice Tests||HTML Practice Tests|
|HTML 5 Practice Tests||Zend Practice Tests|
|PHP and Jquery Practice Tests||J Query Practice Tests|
|CodeIgniter Practice Tests||Dynamic HTML Practice Tests|
J Query Tutorial
Selecting Elements With Jquery
Beyond The Basics
Faster, Simpler, More Fun
Html Form Enhancements From Scratch
Html Form Enhancements With Plugins
Interface Components From Scratch
User Interfaces With Jquery Ui
Jquery Ui Theming
Jquery, Ajax, Data Formats: Html, Xml, Json, Jsonp
Using Jquery In Large Projects
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.