I am using the following widget http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/ It has worked great so far, but I need some help in adding attributes. In using Firebug, I've noticed that by simply clicking on the checkbox the checked attribute does not appear as I would expect it to. In my code, I've modified the widget, I've been able to add code to remove the attribute of checked.
this.removeAttribute(\'checked\'); this.checked=false;
if the item was checked beforehand. I've been successful in using this code
this.setAttribute(\'checked\', \'checked\'); this.checked=true;
if the item was unchecked when the page loads.
My problem is coming when I need to be able to utilize both sets of code on the checkbox, I've attempted the following
onclick="if($(this).attr(\'checked\') == \'true\') { this.setAttribute(\'checked\', \'checked\'); this.checked=true; } else { this.removeAttribute(\'checked\'); this.checked=false; }
the code will remove the attribute of checked (if checked before hand on page load), but when I attempt to click on the checkbox to add the attribute (if not checked on page load), nothing happens.
Thanks for any help, and sorry for my poor coding.
The checked attribute can be used with <input type="checkbox"> and <input type="radio"> . The checked attribute can also be set after the page load, with a JavaScript.
The <input> element contains the type and id attribute. When user click on the button, the jQuery function is called. We use $(selector). attr() method to add the attributes.
According to the W3C forms specification, the checked attribute is a boolean attribute, which means the corresponding property is true if the attribute is present at all—even if, for example, the attribute has no value or is set to empty string value or even "false". This is true of all boolean attributes.
The :checked selector works for checkboxes, radio buttons, and options of select elements. To retrieve only the selected options of select elements, use the :selected selector.
$(this).prop('checked',false)
or
$(this).prop('checked',true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With