In the final twain of articles, I bring shared a twain of useful jQuery tips like reloading spider web page in addition to working alongside tag selectors. Today, I'll present yous how to banking concern gibe or uncheck a item checkbox using jQuery, i of the nearly pop JavaScript framework. jQuery provides CSS similar selectors which tin brand this form of chore trivial. If yous remember, inward HTML a checkbox is checked if the "checked" attribute is acquaint in addition to its value is non false, otherwise, it's unchecked. By using jQuery role prop() yous tin dynamically add together this attribute or if acquaint nosotros tin alter its value i.e. checked=true to brand the checkbox checked in addition to checked=false to grade the checkbox unchecked.
Though yous should retrieve that prop() role is alone available from jQuery 1.6 version in addition to if yous are running on lower jQuery version in addition to then yous tin also exercise attr() to check/uncheck a item checkbox.
Some of yous mightiness inquiry that should yous acquire jQuery now, Well, I intend yous should. Though it has lost about of its charms to Angular, React, in addition to Vue JS but if yous are non using those frameworks, jQuery tin yet locomote a lifesaver to perform mutual spider web evolution task.
Web Development is a constantly changing infinite but non every projection or fellowship adopt them hence fast. That's why yous notice a lot of companies in addition to projects yet using jQuery in addition to fifty-fifty patently onetime HTML alongside JavaScript.
Btw, if yous are novel into spider web evolution space, I strongly advise yous conk through The Web Developer Bootcamp past times Colt Steele at to the lowest degree once. Web Development is a vast expanse in addition to yous demand to know a lot of tools in addition to technologies to acquire a amount stack developer. This course of didactics volition non alone learn yous jQuery but also all other of import technologies yous demand to acquire a ameliorate Web Developer.
Anyway, let's simply to the chore inward hand.
You tin also exercise a class selector if at that topographic point is a bird applied to all the checkboxes or yous tin also exercise chemical portion selector similar input[type='checkbox'] to guide all checkboxes.
Depending on whether yous desire to apply the alter to i chemical portion or multiple elements, at that topographic point are a twain of ways to exercise it inward jQuery. I advise yous banking concern gibe The Complete jQuery Course to run into the amount listing of selectors.
Once the checkbox is selected, nosotros are calling prop() role every bit prop( "checked", truthful ) to banking concern gibe the checkbox in addition to prop( "checked", imitation ) to uncheck the checkbox.
When yous salve this code every bit test.html and opened upward inward a browser e.g. cyberspace explorer, chrome, firefox, or windows edge, yous volition run into the next screen:
You tin run into at that topographic point are 2 buttons in addition to a checkbox is acquaint on the page. If yous click the "check the checkbox" push clit in addition to then the checkbox volition locomote checked, every bit shown inward the next screenshot:
Though yous should retrieve that prop() role is alone available from jQuery 1.6 version in addition to if yous are running on lower jQuery version in addition to then yous tin also exercise attr() to check/uncheck a item checkbox.
Some of yous mightiness inquiry that should yous acquire jQuery now, Well, I intend yous should. Though it has lost about of its charms to Angular, React, in addition to Vue JS but if yous are non using those frameworks, jQuery tin yet locomote a lifesaver to perform mutual spider web evolution task.
Web Development is a constantly changing infinite but non every projection or fellowship adopt them hence fast. That's why yous notice a lot of companies in addition to projects yet using jQuery in addition to fifty-fifty patently onetime HTML alongside JavaScript.
Btw, if yous are novel into spider web evolution space, I strongly advise yous conk through The Web Developer Bootcamp past times Colt Steele at to the lowest degree once. Web Development is a vast expanse in addition to yous demand to know a lot of tools in addition to technologies to acquire a amount stack developer. This course of didactics volition non alone learn yous jQuery but also all other of import technologies yous demand to acquire a ameliorate Web Developer.
Anyway, let's simply to the chore inward hand.
How to Check/Uncheck checkboxes using jQuery
Here is a unproblematic jQuery instance to present yous how to banking concern gibe in addition to uncheck a item checkbox. In this example, nosotros are selecting i item checkbox using ID selector, if yous desire to guide multiple checkboxes.You tin also exercise a class selector if at that topographic point is a bird applied to all the checkboxes or yous tin also exercise chemical portion selector similar input[type='checkbox'] to guide all checkboxes.
Depending on whether yous desire to apply the alter to i chemical portion or multiple elements, at that topographic point are a twain of ways to exercise it inward jQuery. I advise yous banking concern gibe The Complete jQuery Course to run into the amount listing of selectors.
Once the checkbox is selected, nosotros are calling prop() role every bit prop( "checked", truthful ) to banking concern gibe the checkbox in addition to prop( "checked", imitation ) to uncheck the checkbox.
jQuery Example to Select Checkbox
Here is a working example:<html> <head> <title>How to check/uncheck a checkbox using jQuery</title> </head> <body> <h2>Checking in addition to Unchecking a Check box using jQuery</h2> <div id="plateform"> <input id = "myCheckbox" type="checkbox"> H5N1 CheckBox</input> </div> <button id="btn_check">check the checkbox</button> <button id="btn_uncheck">uncheck the checkbox</button> <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script> <script> $(document).ready(function() { $("#btn_check").click(function(){ $("#myCheckbox").prop("checked", true); }); $("#btn_uncheck").click(function(){ $("#myCheckbox").prop("checked", false); }); }); </script> </body> </html>
When yous salve this code every bit test.html and opened upward inward a browser e.g. cyberspace explorer, chrome, firefox, or windows edge, yous volition run into the next screen:
You tin run into at that topographic point are 2 buttons in addition to a checkbox is acquaint on the page. If yous click the "check the checkbox" push clit in addition to then the checkbox volition locomote checked, every bit shown inward the next screenshot:
books) How to acquire electrical current URL, Parameters, in addition to Hash using jQuery? (solution) How to modify to a greater extent than than i chemical portion inward i line? (example) jQuery Hello World Example (program) Free jQuery eBooks in addition to PDFs (download) How to exercise to a greater extent than than i jQuery UI DatePicker inward JSP page? (example) How to exercise tab-based UI using jQuery? (example) Top twenty jQuery Interview Questions for Java Web Developers (list) How to redirect a page URL using jQuery in addition to JavaScript? (solution) How to download jQuery dynamically inward a spider web page? (solution) 10 Frameworks Java in addition to Web developer should acquire (frameworks) The React JS Roadmap - Guide to acquire Moder Web developer (roadmap)
Thanks for reading this article hence far. If yous similar this jQuery tutorial in addition to then delight percentage alongside your friends in addition to colleagues. If yous bring whatsoever inquiry or feedback in addition to then delight driblet a comment.