Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Attribute From Input Checkbox in another div

Is it possible to remove the input type checkbox checked attribute on click of id="chk1" checkbox.

<div class="index1" id="test1">
    <h2>testing1</h2>
    <div class="str">
        <ul>
            <li class="nvc1">
                <input type="checkbox" value="in1" id="chk2" checked="checked" />
                <div class="checkbox-select">str1</div>
                <div class="checkbox-deselect">str2</div>
            </li>
        </ul>
    </div>
</div>
<div class="index2" id="test2">
    <h2>testing2</h2>
    <div class="string">
        <ul>
            <li class="nv1">
                <input type="checkbox" value="in1" id="chk1" />
                <div class="checkbox-select">lblstr1</div>
                <div class="checkbox-deselect">lblstr2</div>
            </li>
        </ul>
    </div>
</div>

Is there any reference for this/

Thanks, ShailShin

like image 695
ShailShin Avatar asked Feb 03 '26 05:02

ShailShin


2 Answers

I suggest this:

$("#chk1").on("change", function(){
    $("#chk2").prop("checked", !$(this).prop("checked"));
});

Change #chk2 checked status depend on #chk1.

JSFiddle

like image 60
Alex Char Avatar answered Feb 04 '26 17:02

Alex Char


In JQuery you can use:

jQuery('#chk1').click(function()
{
    jQuery('#chk1').removeAttr('checked');
});

But does it makes sense? :-)

like image 44
dns_nx Avatar answered Feb 04 '26 18:02

dns_nx