Вопрос

I have some jquery that unchecks all the checkboxes and then if one gets checked then it will uncheck all the others! I want to exclude a div on the page with some checkboxes from this!

The div to be excluded has class="addon"..

$(document).ready(function (){
$(function(){
    $('input:checkbox').prop('checked', false)
    $('input:checkbox').click(function(){
        if($(this).is(':checked')){
            $('input:checkbox').not(this).prop('checked', false);        
        }
    });
})
recal();

});

Or how can i make the above code apply to only checkboxes inside a div with a class name of notaddon..instead of all the checkboxes on the page! ???

( EDIT: I actually Butchered the question but Roger gave me exactly what i asked for even tho its not what i meant i gave roger the check! Funny enough it was till i seen Pratik response that i realised i asked the wrong question! so he should get some credit..)

Это было полезно?

Решение

Use this

For example I want to get checkbox checked with in a div with class test

HTML

<div class="test"><input type="checkbox" id="test"/></div>
<input type="checkbox" id="test1"/>

jQuery

$(".test input:checkbox").prop('checked', true); 

Or if I have understood correctly you might want this code of yours

 $('.notaddon input:checkbox').prop('checked', false)
    $('.notaddon input:checkbox').click(function(){
        if($(this).is(':checked')){
            $('.notaddon input:checkbox').not(this).prop('checked', false);        
        }
    });

Hope this helps

Другие советы

After this code write another code for all checkbox inside div and uncheck the propeties of checkbox.

$('#yourExcludeDivID').find('input[type=checkbox]:checked').removeAttr('checked');

if you want to remove the checkbox completely from div then use

$('#yourExcludeDivID').find('input[type=checkbox]:checked').remove();

$('input:checkbox', '#myDivId') will give you all checkboxes contained in a div with id="myDivId"

So in your case it would be $('input:checkbox', '.notaddon')

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top