views:

49

answers:

3
  <div id="a_all">
  <div>&nbsp;&nbsp;&nbsp;&nbsp<input type="checkbox" name="m_a">1</input<br></div>
  <div>&nbsp;&nbsp;&nbsp;&nbsp<input type="checkbox" name="m_a">2</input<br></div>
  <div>&nbsp;&nbsp;&nbsp;&nbsp<input type="checkbox" name="m_a">3</input<br></div>
  <div>&nbsp;&nbsp;&nbsp;&nbsp<input type="checkbox" name="m_a">4</input<br></div>
  </div>

If the first check box is selected how to remove the full div the checkbox in using jquery

+2  A: 

Hi rajiv

Try this

<html>
    <head></head>
    <body>
        <div id="all">
        <div>1<input type=checkbox name="test" value="10"/></div>
        <div>2<input type=checkbox name="test" value="20"/></div>
        <div>3<input type=checkbox name="test" value="30"/></div>
        </div>
    </body>
</html>
​

jquery

$("#all input").click(function() {
    alert($("input:checked").val());
    $(this).parent().remove();
});​

live demo

http://jsfiddle.net/QpEVe/1/

JapanPro
A: 
jQuery('input[type=checkbox]').bind('change',_handleCheckboxChange);

function _handleCheckboxChange(e)
{
   var _elm=jQuery(e.target);
   if(_elm.filter(':checked'))
   {
       _elm.parents('div:first').remove()
   }
}
Praveen Prasad
A: 

You can do like this to bind the click even to each checkbox. It will remove the parent element of each checkbox you click:

$(function(){
  $('#a_all :checkbox').click(function(){
    $(this).parent().remove();
  });
});
Guffa