javascript - Add attribute 'checked' on click jquery -


I'm trying to figure out how to add the "check" attribute on the How to Click checkbox. The reason for this is that I am checking a checkbox; I can save my local storage, like when refreshing the page in the form of html, it checks that the checkbox is checked. So far if I check it, it fades the parent, but if I save it and reload it remains faded, but the checkbox is unchecked.

I have tried $ (this) .attr ('checked'); But it does not want to add the check.

EDIT: After reading the comments it seems that I was not clear. My default input tag is:

  & lt; Input type = "checkbox" class = "done" & gt;  

I should be at the top when I click on the checkbox, it checks the "end" pre:

   

I need to do this when I save the html in local storage, when it loads, it checks the checkbox as checked

  $ (".done"). Live ("click", function () {if ($ (this) .Parent (). Find ('. Editor'). (': Visible')) {var editvar = $ (this) .Parent () ('Input [name = "tester"]'). Val (); $ (this) .Parent () Find ('Editor'). Fadeaut ('slow'); $ (this) .Parent (). ('. Content'). Text (edit); $ (this) .Parent (). ('Content'). ('Slow');} if ($ (this). This (': check' ) $ {This ($)} parent (). Feedto ('slow', 0.5); $ (this) .attr ('checked'); // this line} and {$ (this) .Parent (). ('Slow', 1); $ (this) .removeAttr ('checked');}});  

It seems that this is one of the rare occasions on which the feature is actually used Is fair in JQuery's attr () method will not help you because in most cases (including this), it actually sets one asset, is not a feature, the choice of its name looks a bit stupid. Strong> [Update: since jQuery 1.6.1]

There are some problems with the IOM in the DOM setAttribute method but in this case it should be fine:

  this.setAttribute ("check", "checked");  

In IE, it will always really check the checkbox. In other browsers, if the user has already checked and unchecked the checkbox, there will be no visual effect of the setting's feature. Therefore, if you want to confirm the checkbox, as well as the checked attribute, then you have to set the checked property as well:

< Pre> this.setAttribute ("check", "check"); This.checked = true; To uncheck the

checkbox and remove the attribute, do the following:

  this.setAttribute ("check", ""); // This is for IE. Remove attitudes ("check"); // For other browsers this Check = false;  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -