mardi 4 avril 2017

how to remove elements from a div when checkbox is unchecked?

how to remove elements from a div when checkbox is unchecked ?

    <script>
    function dispCmpName(id) {
        var campdip = $('#camp' + id).html();
        if($("#campaign-name-disp").val().search(""+campdip) === -1){
            $("#campaign-name-disp").append(campdip +"<br/>");
        }
    }
    </script>
    <body>
<div><p id="campaign-name-disp"></p></div>
        <input type="checkbox" class="checkBoxClass1" id="${campDetails.campaignId}" name="campaignId" value="${campDetails.campaignId}"          onclick="dispCmpName(${campDetails.campaignId})"/>
         <td id="camp${campDetails.campaignId}">${campDetails.campaignName}</td>
    </body>

whenever i check a check box the dispCmpName function gets called and adds the campaign name to the div campaign-name-disp. And when i uncheck the checkbox i want to remove that campaign name from my div, but as per my code the campaign name is getting added again as i have an on click function. Could anyone help me out in how to remove the name from the div.




Aucun commentaire:

Enregistrer un commentaire