Uncheck checkbox on click button












1















I am appending button on checkbox click, but need to uncheck when I close the appended button.



$(".left-menu input[name='freeAsset']").click(function() {
if ($(this).is(':checked')) {
$('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">' + $(this).parent('div').children('span').text() + '<span aria-hidden="true" id="' + this.id + '">×</span></button></li>');
$('.filter-label li .btn-close span').click(function() {
$(this).closest('li').remove();
});
} else {
$(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
return $(this).parent('li').length > 0;
}).remove();
}
});


FIDDLE DEMO










share|improve this question

























  • do you want to uncheck the checkbox after closing the button?

    – Kiranramchandran
    Nov 15 '18 at 12:21
















1















I am appending button on checkbox click, but need to uncheck when I close the appended button.



$(".left-menu input[name='freeAsset']").click(function() {
if ($(this).is(':checked')) {
$('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">' + $(this).parent('div').children('span').text() + '<span aria-hidden="true" id="' + this.id + '">×</span></button></li>');
$('.filter-label li .btn-close span').click(function() {
$(this).closest('li').remove();
});
} else {
$(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
return $(this).parent('li').length > 0;
}).remove();
}
});


FIDDLE DEMO










share|improve this question

























  • do you want to uncheck the checkbox after closing the button?

    – Kiranramchandran
    Nov 15 '18 at 12:21














1












1








1








I am appending button on checkbox click, but need to uncheck when I close the appended button.



$(".left-menu input[name='freeAsset']").click(function() {
if ($(this).is(':checked')) {
$('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">' + $(this).parent('div').children('span').text() + '<span aria-hidden="true" id="' + this.id + '">×</span></button></li>');
$('.filter-label li .btn-close span').click(function() {
$(this).closest('li').remove();
});
} else {
$(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
return $(this).parent('li').length > 0;
}).remove();
}
});


FIDDLE DEMO










share|improve this question
















I am appending button on checkbox click, but need to uncheck when I close the appended button.



$(".left-menu input[name='freeAsset']").click(function() {
if ($(this).is(':checked')) {
$('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">' + $(this).parent('div').children('span').text() + '<span aria-hidden="true" id="' + this.id + '">×</span></button></li>');
$('.filter-label li .btn-close span').click(function() {
$(this).closest('li').remove();
});
} else {
$(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
return $(this).parent('li').length > 0;
}).remove();
}
});


FIDDLE DEMO







jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 12:06









Zakaria Acharki

55.7k134370




55.7k134370










asked Nov 15 '18 at 11:50









Adam PavlovAdam Pavlov

136111




136111













  • do you want to uncheck the checkbox after closing the button?

    – Kiranramchandran
    Nov 15 '18 at 12:21



















  • do you want to uncheck the checkbox after closing the button?

    – Kiranramchandran
    Nov 15 '18 at 12:21

















do you want to uncheck the checkbox after closing the button?

– Kiranramchandran
Nov 15 '18 at 12:21





do you want to uncheck the checkbox after closing the button?

– Kiranramchandran
Nov 15 '18 at 12:21












3 Answers
3






active

oldest

votes


















1














From question i understand that OP need to uncheck the check box after closing the button. So i did the following way.



$('.filter-label li .btn-close span').click(function(){
$('input[type=checkbox][id='+$(this).attr('id') +']').prop('checked',false);// Newly added code to uncheck the checkbox.
$(this).closest('li').remove();
});


DEMO HERE






share|improve this answer































    0














    Working fiddle.



    Since you're appendin an li element when the user check, you need to remove the parent li not the button itself when the user uncheck, the just add .closest('li') before removing :



    $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
    return $(this).parent('li').length > 0;
    }).closest('li').remove();
    ___^^^^^^^^^^^^^





    share|improve this answer
























    • @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

      – Zakaria Acharki
      Nov 15 '18 at 13:47



















    0














    In else you trying to select button and remove it using .remove(). So you should select li parent of button using .parent() and remove it.






    $(".left-menu input[name='freeAsset']").click(function() {
    if($(this).is(':checked')) {
    $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
    $('.filter-label li .btn-close span').click(function(){
    $(this).closest('li').remove();
    });
    } else {
    $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
    return $(this).parent('li').length > 0;
    }).parent().remove();
    }
    });

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <ul class="left-menu">
    <li>
    <div class="label-cont clearfix">
    <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
    <label for="Skills1" class="chk"></label>
    <span class="txt">Soft Skills</span>
    </div>
    </li>
    <li>
    <div class="label-cont clearfix">
    <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
    <label for="Skills2" class="chk"></label>
    <span class="txt">Technical Skills</span>
    </div>
    </li>
    </ul>
    <ul class="filter-label clearfix search_lable"></ul>





    Also you can use simpler code as shown in bottom






    $(".left-menu input[name='freeAsset']").click(function() {
    var text = $(this).parent('div').children('span').text();
    if ($(this).is(':checked'))
    $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
    else
    $(".search_lable li button:contains("+text+")").parent().remove();
    });
    $(document).on('click', '.filter-label li .btn-close span', function(){
    $(this).closest('li').remove();
    });

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <ul class="left-menu">
    <li>
    <div class="label-cont clearfix">
    <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
    <label for="Skills1" class="chk"></label>
    <span class="txt">Soft Skills</span>
    </div>
    </li>
    <li>
    <div class="label-cont clearfix">
    <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
    <label for="Skills2" class="chk"></label>
    <span class="txt">Technical Skills</span>
    </div>
    </li>
    </ul>
    <ul class="filter-label clearfix search_lable"></ul>








    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318862%2funcheck-checkbox-on-click-button%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      From question i understand that OP need to uncheck the check box after closing the button. So i did the following way.



      $('.filter-label li .btn-close span').click(function(){
      $('input[type=checkbox][id='+$(this).attr('id') +']').prop('checked',false);// Newly added code to uncheck the checkbox.
      $(this).closest('li').remove();
      });


      DEMO HERE






      share|improve this answer




























        1














        From question i understand that OP need to uncheck the check box after closing the button. So i did the following way.



        $('.filter-label li .btn-close span').click(function(){
        $('input[type=checkbox][id='+$(this).attr('id') +']').prop('checked',false);// Newly added code to uncheck the checkbox.
        $(this).closest('li').remove();
        });


        DEMO HERE






        share|improve this answer


























          1












          1








          1







          From question i understand that OP need to uncheck the check box after closing the button. So i did the following way.



          $('.filter-label li .btn-close span').click(function(){
          $('input[type=checkbox][id='+$(this).attr('id') +']').prop('checked',false);// Newly added code to uncheck the checkbox.
          $(this).closest('li').remove();
          });


          DEMO HERE






          share|improve this answer













          From question i understand that OP need to uncheck the check box after closing the button. So i did the following way.



          $('.filter-label li .btn-close span').click(function(){
          $('input[type=checkbox][id='+$(this).attr('id') +']').prop('checked',false);// Newly added code to uncheck the checkbox.
          $(this).closest('li').remove();
          });


          DEMO HERE







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 12:26









          KiranramchandranKiranramchandran

          1,9801028




          1,9801028

























              0














              Working fiddle.



              Since you're appendin an li element when the user check, you need to remove the parent li not the button itself when the user uncheck, the just add .closest('li') before removing :



              $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
              return $(this).parent('li').length > 0;
              }).closest('li').remove();
              ___^^^^^^^^^^^^^





              share|improve this answer
























              • @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

                – Zakaria Acharki
                Nov 15 '18 at 13:47
















              0














              Working fiddle.



              Since you're appendin an li element when the user check, you need to remove the parent li not the button itself when the user uncheck, the just add .closest('li') before removing :



              $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
              return $(this).parent('li').length > 0;
              }).closest('li').remove();
              ___^^^^^^^^^^^^^





              share|improve this answer
























              • @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

                – Zakaria Acharki
                Nov 15 '18 at 13:47














              0












              0








              0







              Working fiddle.



              Since you're appendin an li element when the user check, you need to remove the parent li not the button itself when the user uncheck, the just add .closest('li') before removing :



              $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
              return $(this).parent('li').length > 0;
              }).closest('li').remove();
              ___^^^^^^^^^^^^^





              share|improve this answer













              Working fiddle.



              Since you're appendin an li element when the user check, you need to remove the parent li not the button itself when the user uncheck, the just add .closest('li') before removing :



              $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() + ")").filter(function() {
              return $(this).parent('li').length > 0;
              }).closest('li').remove();
              ___^^^^^^^^^^^^^






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 15 '18 at 12:01









              Zakaria AcharkiZakaria Acharki

              55.7k134370




              55.7k134370













              • @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

                – Zakaria Acharki
                Nov 15 '18 at 13:47



















              • @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

                – Zakaria Acharki
                Nov 15 '18 at 13:47

















              @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

              – Zakaria Acharki
              Nov 15 '18 at 13:47





              @Adam could you please tell us why you've accepted the newest answer to your question what is almost a copy of the old answers here?

              – Zakaria Acharki
              Nov 15 '18 at 13:47











              0














              In else you trying to select button and remove it using .remove(). So you should select li parent of button using .parent() and remove it.






              $(".left-menu input[name='freeAsset']").click(function() {
              if($(this).is(':checked')) {
              $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
              $('.filter-label li .btn-close span').click(function(){
              $(this).closest('li').remove();
              });
              } else {
              $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
              return $(this).parent('li').length > 0;
              }).parent().remove();
              }
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <ul class="left-menu">
              <li>
              <div class="label-cont clearfix">
              <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
              <label for="Skills1" class="chk"></label>
              <span class="txt">Soft Skills</span>
              </div>
              </li>
              <li>
              <div class="label-cont clearfix">
              <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
              <label for="Skills2" class="chk"></label>
              <span class="txt">Technical Skills</span>
              </div>
              </li>
              </ul>
              <ul class="filter-label clearfix search_lable"></ul>





              Also you can use simpler code as shown in bottom






              $(".left-menu input[name='freeAsset']").click(function() {
              var text = $(this).parent('div').children('span').text();
              if ($(this).is(':checked'))
              $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
              else
              $(".search_lable li button:contains("+text+")").parent().remove();
              });
              $(document).on('click', '.filter-label li .btn-close span', function(){
              $(this).closest('li').remove();
              });

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <ul class="left-menu">
              <li>
              <div class="label-cont clearfix">
              <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
              <label for="Skills1" class="chk"></label>
              <span class="txt">Soft Skills</span>
              </div>
              </li>
              <li>
              <div class="label-cont clearfix">
              <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
              <label for="Skills2" class="chk"></label>
              <span class="txt">Technical Skills</span>
              </div>
              </li>
              </ul>
              <ul class="filter-label clearfix search_lable"></ul>








              share|improve this answer






























                0














                In else you trying to select button and remove it using .remove(). So you should select li parent of button using .parent() and remove it.






                $(".left-menu input[name='freeAsset']").click(function() {
                if($(this).is(':checked')) {
                $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                $('.filter-label li .btn-close span').click(function(){
                $(this).closest('li').remove();
                });
                } else {
                $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
                return $(this).parent('li').length > 0;
                }).parent().remove();
                }
                });

                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                <ul class="left-menu">
                <li>
                <div class="label-cont clearfix">
                <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                <label for="Skills1" class="chk"></label>
                <span class="txt">Soft Skills</span>
                </div>
                </li>
                <li>
                <div class="label-cont clearfix">
                <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                <label for="Skills2" class="chk"></label>
                <span class="txt">Technical Skills</span>
                </div>
                </li>
                </ul>
                <ul class="filter-label clearfix search_lable"></ul>





                Also you can use simpler code as shown in bottom






                $(".left-menu input[name='freeAsset']").click(function() {
                var text = $(this).parent('div').children('span').text();
                if ($(this).is(':checked'))
                $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                else
                $(".search_lable li button:contains("+text+")").parent().remove();
                });
                $(document).on('click', '.filter-label li .btn-close span', function(){
                $(this).closest('li').remove();
                });

                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                <ul class="left-menu">
                <li>
                <div class="label-cont clearfix">
                <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                <label for="Skills1" class="chk"></label>
                <span class="txt">Soft Skills</span>
                </div>
                </li>
                <li>
                <div class="label-cont clearfix">
                <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                <label for="Skills2" class="chk"></label>
                <span class="txt">Technical Skills</span>
                </div>
                </li>
                </ul>
                <ul class="filter-label clearfix search_lable"></ul>








                share|improve this answer




























                  0












                  0








                  0







                  In else you trying to select button and remove it using .remove(). So you should select li parent of button using .parent() and remove it.






                  $(".left-menu input[name='freeAsset']").click(function() {
                  if($(this).is(':checked')) {
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  $('.filter-label li .btn-close span').click(function(){
                  $(this).closest('li').remove();
                  });
                  } else {
                  $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
                  return $(this).parent('li').length > 0;
                  }).parent().remove();
                  }
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>





                  Also you can use simpler code as shown in bottom






                  $(".left-menu input[name='freeAsset']").click(function() {
                  var text = $(this).parent('div').children('span').text();
                  if ($(this).is(':checked'))
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  else
                  $(".search_lable li button:contains("+text+")").parent().remove();
                  });
                  $(document).on('click', '.filter-label li .btn-close span', function(){
                  $(this).closest('li').remove();
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>








                  share|improve this answer















                  In else you trying to select button and remove it using .remove(). So you should select li parent of button using .parent() and remove it.






                  $(".left-menu input[name='freeAsset']").click(function() {
                  if($(this).is(':checked')) {
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  $('.filter-label li .btn-close span').click(function(){
                  $(this).closest('li').remove();
                  });
                  } else {
                  $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
                  return $(this).parent('li').length > 0;
                  }).parent().remove();
                  }
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>





                  Also you can use simpler code as shown in bottom






                  $(".left-menu input[name='freeAsset']").click(function() {
                  var text = $(this).parent('div').children('span').text();
                  if ($(this).is(':checked'))
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  else
                  $(".search_lable li button:contains("+text+")").parent().remove();
                  });
                  $(document).on('click', '.filter-label li .btn-close span', function(){
                  $(this).closest('li').remove();
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>








                  $(".left-menu input[name='freeAsset']").click(function() {
                  if($(this).is(':checked')) {
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  $('.filter-label li .btn-close span').click(function(){
                  $(this).closest('li').remove();
                  });
                  } else {
                  $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
                  return $(this).parent('li').length > 0;
                  }).parent().remove();
                  }
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>





                  $(".left-menu input[name='freeAsset']").click(function() {
                  if($(this).is(':checked')) {
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ $(this).parent('div').children('span').text() +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  $('.filter-label li .btn-close span').click(function(){
                  $(this).closest('li').remove();
                  });
                  } else {
                  $(".search_lable").find("button:contains(" + $(this).parent('div').children('span').text() +")").filter(function () {
                  return $(this).parent('li').length > 0;
                  }).parent().remove();
                  }
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>





                  $(".left-menu input[name='freeAsset']").click(function() {
                  var text = $(this).parent('div').children('span').text();
                  if ($(this).is(':checked'))
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  else
                  $(".search_lable li button:contains("+text+")").parent().remove();
                  });
                  $(document).on('click', '.filter-label li .btn-close span', function(){
                  $(this).closest('li').remove();
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>





                  $(".left-menu input[name='freeAsset']").click(function() {
                  var text = $(this).parent('div').children('span').text();
                  if ($(this).is(':checked'))
                  $('.search_lable').append('<li><button type="button" class="btn-close image" aria-label="Close" style="display: inline-block;">'+ text +'<span aria-hidden="true" id="'+this.id+'">×</span></button></li>');
                  else
                  $(".search_lable li button:contains("+text+")").parent().remove();
                  });
                  $(document).on('click', '.filter-label li .btn-close span', function(){
                  $(this).closest('li').remove();
                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <ul class="left-menu">
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills1">
                  <label for="Skills1" class="chk"></label>
                  <span class="txt">Soft Skills</span>
                  </div>
                  </li>
                  <li>
                  <div class="label-cont clearfix">
                  <input type="checkbox" name="freeAsset" value="valuable" id="Skills2">
                  <label for="Skills2" class="chk"></label>
                  <span class="txt">Technical Skills</span>
                  </div>
                  </li>
                  </ul>
                  <ul class="filter-label clearfix search_lable"></ul>






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 15 '18 at 12:14

























                  answered Nov 15 '18 at 12:01









                  MohammadMohammad

                  15.7k123664




                  15.7k123664






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318862%2funcheck-checkbox-on-click-button%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine