check all

Check the parent nodes only and exclude the child nodes

by Suraj Raj Shrestha

HTML

<input type="checkbox" class="chkAll">Check All <br />
<input type="checkbox" class="chkTitle">Title <br />
<input type="checkbox" class="chkControls">Auto Play <br />
<input type="checkbox" class="chkControls">Loop Until Stopped <br />
<input type="checkbox" class="chkControls">Mute Enabled <br />

JavaScript

$(".chkAll").on("click", function(){
    var isChecked = $(this).prop("checked");
    $("input:checkbox").each(function(){
        var className = $(this).attr("class");
        if(className != "chkControls"){
            $(this).prop("checked", isChecked);
        }
    });
});