Domanda

<div class="startd">
    <span class="wish">Hello</span>
    <span class="check1">
    <input type="checkbox" name="standard" value="matrix1"><span class="checktext">matrix1</span><br />
    <input type="checkbox" name="standard" value="matrix1"><span class="checktext">matrix2</span><br />
    <input type="checkbox" name="standard" value="matrix1"><span class="checktext">matrix3</span><br />
            </span>
</div>
<a class="update">checked</a>
<div class="Select">
</div>
<script>
 $(".update").click(function(){
   var a=$("span.check1")
   a.each(function(index, elementDiv){
     var div= $(elementDiv);
     var input = $(elementDiv).each('input');
     var check = input.is(":checked");
     if(check){
      //the below line adds content clone to target div
        $(".Select").append(div);
  }
});
</script>

Hai ... i need a help. actually i want print the check box in the "select" div tag which is checked can u tell me my mistake

È stato utile?

Soluzione

You can do this:

// Get all the checked checkbox's
var $checkbox = $("span.check1 :checkbox:checked")

// Loop through only checked ones
$checkbox.each(function () {

    //the below line adds content clone to target div
    $(".Select").append($(this).clone());
    $(".Select").append($(this).next('span').clone());
});

Altri suggerimenti

your inputs are inside the span as direct children. The code you have written would work if the inputs each were inside a div inside the span.

Your Current structure is: .check1>input . The code works for .check1>div>input

<script>
 var a=$("span.check1")
 a.each(function(index, checkbox){

 var input = $(checkbox);
 var check = input.is(":checked");
 if(check){
 //the below line adds content clone to target div
 $(".Select").append(input);
            }
        });
</script>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top