Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this.elem.prop is not a function

Tags:

jquery

I need to select all cities under states (eg. India) listed. I put a select all:

<input type="checkbox" class="selectall" /> Select All

Then the below error is appearing:

this.elem.prop is not a function

This is my code:

jQuery('.selectall').click(function() {
    stop = false;
    jQuery(this).closest('div').nextAll().each( function() {
        elem = jQuery(this).find('input');
        console.log(elem);
        if (stop || elem.hasClass('selectall')) {
            stop = true;
            return;
        }
        else
            elem.prop("checked", true);
    });
});
like image 845
Ras4U Avatar asked Jan 09 '13 09:01

Ras4U


1 Answers

The prop() method was only added in jQuery 1.6. In previous versions you should use attr().

elem.attr("checked", true);

Note about other answers, elem is already a jQuery object as it was defined on this line: elem = jQuery(this).find('input');, therefore the prop() method would be available if the jQuery version supports it.


UPDATE

To toggle the checkbox, use this:

if (stop || elem.hasClass('selectall')) {
    stop = true;
    return;
}
else
    elem.prop("checked", !elem.is(':checked')); // toggle the checkbox
like image 95
Rory McCrossan Avatar answered Oct 13 '22 19:10

Rory McCrossan