For jQuery 1.6+ :
.attr() is deprecated for properties; use the new .prop() function instead as:
$('#myCheckbox').prop('checked', true); // Checks it $('#myCheckbox').prop('checked', false); // Unchecks it
For jQuery < 1.6:
To check/uncheck a checkbox, use the attribute checked
and alter that. With jQuery you can do:
$('#myCheckbox').attr('checked', true); // Checks it $('#myCheckbox').attr('checked', false); // Unchecks it
Cause you know, in HTML, it would look something like:
<input type="checkbox" id="myCheckbox" checked="checked" /> <!-- Checked --> <input type="checkbox" id="myCheckbox" /> <!-- Unchecked -->
However, you cannot trust the .attr() method to get the value of the checkbox (if you need to). You will have to rely in the .prop() method.
Related Posts:
- jQuery dialog popup
- keycode 13 is for which key
- How to change the text of a button in jQuery?
- jQueryUI dialog width
- How to use radio on change event?
- Form Submit jQuery does not work
- Icons missing in jQuery UI
- Find out whether radio button is checked with JQuery?
- Slide right to left?
- Check if user is logged in using JQuery
- How to save the state of a drag and drop jQuery UI Sortables front end layout editor?
- How Do I Use jQuery UI In My Plugin
- jQuery UI Datepicker not working
- Custom function to rearrange attachments when creating posts – Almost there
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- possible to make sections in theme customizer sortable and saveable at publish button clicked?
- jQuery does not work in widget backend
- WordPress loads whole jQuery UI library
- Enqueuing jQuery in plug-ins
- How do I get my page to load the jQuery UI Effects library?
- Timepicker-addon doesn’t show – Datepicker works fine?
- Ajax with jQuery UI dialog not working
- WordPress doesn’t Load JQuery Now? Do I need to enqueue JQuery also?
- Override default jquery ui library with newer version
- How to enable the content editor as a droppable target with jQuery-ui?
- Automatic jQuery accordion from header tags
- jQuery UI inside widget on admin page
- Jquery not showing in homepage
- Loading jQuery UI in the head
- Format numeric symbols in titles
- jQuery.accordion isn’t a function even when enqueued
- Override theme style with other CSS on a specific page
- Adding a slider captcha to the comment system
- splitting the URL using jQuery
- Need to change url paramenter of share product pintrest [closed]
- Will the latest Bootstrap work properly with the default WordPress jQuery?
- In WooCommerce product archive, how can you also set the quantity to be added to cart by typing, instead of just by using +/-?
- Rhyzz Repeatable-fields javascript in php and wordpress
- WordPress + BlockUI or a splash page [closed]
- Return an array from get_terms and store as JavaScript array for search autocomplete
- How to prevent plugins from loading jQuery
- Dukapress jQuery(“form.product_update”).livequery is not a function [closed]
- Jquery function working in Dev Console but not otherwise [duplicate]
- Which jQuery packages are included in WordPress 3.1.2?
- Good Solution for Adding jQuery Tabs Anywhere Within WordPress?
- Cannot enqueue jQuery correctly using Google CDN
- Adding jQuery UI elements to WordPress page
- Sorting WP Auctions by date/price?
- How to add custon UI jquery & Fancybox script to WP
- jQuery tabs plugin with callback to fetch data
- Jquery UI Google CSS, from where?
- Uncaught TypeError: jQuery(…).slider is not a function
- datepicker for custom post type admin
- How can i unload effect.min.js file?
- jQuery UI tab does not work in the plugin page
- JQuery UI not loading without explicit loading of jQuery
- Is there a default way in wordpress to create a overlay in the dashboard?
- AJAX Success Function using JS substr() fails in WP 4.1 vs 4.0
- Custom meta box with jQuery.sortable custom post type list
- Recommended Use of Bootstrap, or JQuery-UI in WP/plugin development?
- Removed jQuery script from header.php , any problems?
- “switchEditors is not defined” with wp_editor() in jQuery UI tabs
- Screen Options JavaScript Code
- Portfolio Slideshow Sliders Behaving Oddly When in jQuery Ui Tabs
- Custom Jquery in admin breaks media-upload script
- Drag and Drop Metadata Menu Order
- A carousel slideshow plugin in JavaScript
- jQueryUI draggable doesn’t work in WordPress plugin
- jQuery UI Accordion loading very slow
- Theme style overrides the plugin style
- WordPress live search and filter
- main navigation menu disappear after adding jquery source file
- Slide toggle Jquery UI
- WordPress Thickbox Navigation Issue in Gallery
- jquery Autocomplete
- Overwrite js code using WP_Footer
- why does so many javascript libraries are loaded along with my website?
- Dashboard controls have all stopped working
- How can I add a new lib path without call each one on the header?
- Add jQuery in dashboard when is already added in main plugin page
- Sorting UL Listing Within the TinyMCE Visual Editor in WordPress
- jQuery dialog prints HTML-Tags under WordPress
- WordPress/jQuery pagination plugin for multiple lists
- using jquery autocomplete in wordpress plugin
- JQuery UI plugin not working in IE7?
- Theme variation conflict with jquery select2 dropdown
- How react js and other Javascript Technologies works on WordPress plugin?
- jQuery datepicker not showing on admin menu
- How to enable CORS in flask
- Complex JSON nesting of objects and arrays
- jQuery – Increase the value of a counter when a button is clicked
- Modified wp.media.view.Settings.Gallery in Backbone JS, but editing doesn’t work
- Add Infinite Scroll to Ajax Loaded Category Query
- How to include jQuery when no header and footer on the page
- Jquery on custom-field backend
- jQuery(‘#news-ticker’).cycle is not a function
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Use jQuery and AJAX to get HTML
- PHP and Jquery pass value from form. Update function on DataBase
- Loading a post’s content, into a div outside the loop, when it’s title is selected in a list