`attr ('checked', false)` does not work on IE6

As the name says, I can’t get .attr('checked', false)to work with IE6. I am cloning some HTML, and then before I assign the newly cloned HTML to the element, I will skip it and clear all the checkboxes that are in the newly cloned section, which works fine in all browsers except IE 6.

Here is the code:

    //give each input and select a custom id
    clone.find('input, select').each( function( i ) {

            //get the id attribute
            var id = $(this).attr('id');

            //uncheck all of the tick boxes
            $(this).attr('checked', '');

            //get the name attribute
            var name = $(this).attr('name');

            $(this).attr('name', name+"_"+count)
            $(this).attr('id', id+"_"+count+"_"+i)

    });

    //append the newly created area to the area wrapper
    clone.appendTo('[data-custom="area_wrapper"]');

Is there a way around this problem?

+3
source share
3 answers

Try

.removeAttr("checked")
+3
source

The simplest solution is also optimization:

this.checked = false;

In fact, you can apply this optimization to all of your code:

        //get the id attribute
        var id = this.id;

        //uncheck all of the tick boxes
        this.checked = false;

        //get the name attribute
        var name = this.name;

        this.name = name+"_"+count;
        this.id = id+"_"+count+"_"+i;

, jQuery (attr jQuery 1.6).

http://whattheheadsaid.com/2010/10/utilizing-the-awesome-power-of-jquery-to-access-properties-of-an-element.

+7

There is no HTML attribute "checked = false", only "checked = checked" for checked boxes and nothing for unchecked fields.

use .removeAttr('checked');

+1
source

Source: https://habr.com/ru/post/1774283/


All Articles