Adding a verified attribute via jQuery

I use the following widget http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/ So far it has worked fine, but I need help in adding attributes. When using Firebug, I noticed that just by clicking on the checkmark, the verified attribute does not appear as I would expect. In my code, I changed the widget, I was able to add code to remove the checked attribute.

this.removeAttribute(\'checked\'); this.checked=false;

if the item has been checked in advance. I managed to use this code

this.setAttribute(\'checked\', \'checked\'); this.checked=true; 

if the item was not marked when loading the page.

My problem arises when I need to use both sets of code in this checkbox, I tried to execute 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 checked attribute (if the flag is set before loading on the page), but when I try to click this flag to add the attribute (if it is not set when the page loads), nothing happens.

Thanks for any help and sorry for my poor coding.

+5
source share
3 answers

In jQuery to remove attribute use

this.removeAttr('checked');

and to set the attribute use

this.attr('checked', 'checked');
+14
source

I noticed that just by clicking on the checkbox the checked attribute is not showing

. checked ; HTML, , , reset.

IE , IE . getAttribute/setAttribute IE - HTML-! - , .

defaultChecked. checked? . checked - , .

+2

Firebug , , , checked , .

checked? checked , , .. element.checked true , element.checked .

+1

All Articles