Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery to uncheck all checkboxes within div

Tags:

html

jquery

<div id="termSheetPopup">
    <div style="text-align:center;">
        <select id="termSheetType">
            <option>Internal</option>
            <option>Borrower Facing</option>
        </select>
    </div>

    <input type="checkbox" name="SummaryInformation">Summary Information<br />
    <input type="checkbox" name="ProductLegs">Product Legs<br />
    <input type="checkbox" name="AmortizationOptions">Amortization Options<br />
    <input type="checkbox" name="Values">Values<br />
    <input type="checkbox" name="Rates">Rates<br />
    <input type="checkbox" name="RatesSpecific">Rates (All-In-Rate, PV01)<br />
    <input type="checkbox" name="AmortizationSchedule">Amortization Schedule<br />
    <input type="checkbox" name="SponsorInfo">Sponsor/Affiliate Info<br />
    <input type="checkbox" name="BorrowerInfo">Borrower Info<br />
    <input type="checkbox" name="SponsorContacts">Sponsor/Affiliate Contacts<br />
    <input type="checkbox" name="CashFlows">Cash Flows<br />
    <input type="checkbox" name="PrePayment">Pre-Payment<br />
    <input type="checkbox" name="FutureExposure">Potential Future Exposure<br />
    <input type="checkbox" name="FutureExposureSpecific">Potential Future Exposure (Max Number and Date Only)<br />
    <input type="checkbox" name="History">History<br />
</div>

What's the JQuery to delete all those checkboxes just underneath that div?

like image 984
slandau Avatar asked Feb 10 '11 16:02

slandau


2 Answers

To uncheck all the checkboxes (as the title asks):

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

To delete all the checkboxes (as the question asks):

$('#termSheetPopup').find('input[type=checkbox]:checked').remove();
like image 194
Silver Light Avatar answered Oct 10 '22 23:10

Silver Light


Another approach would be:

Assign a class(just to use as a selector) to each checkbox,

<div id="termSheetPopup">
<div style="text-align:center;">
    <select id="termSheetType">
        <option>Internal</option>
        <option>Borrower Facing</option>
    </select>
</div>

<input type="checkbox" class="chk" name="SummaryInformation">Summary Information<br />
<input type="checkbox" class="chk" name="ProductLegs">Product Legs<br />
<input type="checkbox" class="chk" name="AmortizationOptions">Amortization Options<br />
<input type="checkbox" class="chk" name="Values">Values<br />
<input type="checkbox" class="chk" name="Rates">Rates<br />
<input type="checkbox" class="chk" name="RatesSpecific">Rates (All-In-Rate, PV01)<br />
<input type="checkbox" class="chk" name="AmortizationSchedule">Amortization Schedule<br />
<input type="checkbox" class="chk" name="SponsorInfo">Sponsor/Affiliate Info<br />
<input type="checkbox" class="chk" name="BorrowerInfo">Borrower Info<br />
<input type="checkbox" class="chk" name="SponsorContacts">Sponsor/Affiliate Contacts<br />
<input type="checkbox" class="chk" name="CashFlows">Cash Flows<br />
<input type="checkbox" class="chk" name="PrePayment">Pre-Payment<br />
<input type="checkbox" class="chk" name="FutureExposure">Potential Future Exposure<br />
<input type="checkbox" class="chk" name="FutureExposureSpecific">Potential Future Exposure (Max Number and Date Only)<br />
<input type="checkbox" class="chk" name="History">History<br />

And use below line to check all checkboxes:

$('.chk').attr("checked", true);

For deleting, I guess you want to delete checkbox along with the title. Insert them into a div with some id. And remove that div:

 <div id="someid"><input type="checkbox" class="chk" name="SummaryInformation">Summary Information</div> 

Use below code to delete:

$('#someid').remove()

This will remove checkbox as wel as the text since the div is removed.

like image 2
Pradeep Avatar answered Oct 10 '22 22:10

Pradeep