JQuery - travel inside of elements using Each() function -


how travel inside elements in jquery using each function?

consider elements structure:

<div id="first-div">      <div id="check-div1">         <input type="checkbox" name="choices" id="mobile-check"             value="mobile">mobile     </div>      <div id="check-div2">         <input type="checkbox" name="choices" id="charger-check"             value="charger">charger     </div>      <div id="check-div3">         <input type="checkbox" name="choices" id="headphone-check"             value="head phone">head phone     </div> </div> 

i want print value of each checkbox in alert using each method.

i tried following

    $("#first-div").each(function(){         alert($(this).id.div); // struck here travel inner of first-div     }); 

$('#first-div div').each(function() {    var val = $(this).find('input').val();    alert(val)      })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="first-div">      <div id="check-div1">      <input type="checkbox" name="choices" id="mobile-check" value="mobile">mobile    </div>      <div id="check-div2">      <input type="checkbox" name="choices" id="charger-check" value="charger">charger    </div>      <div id="check-div3">      <input type="checkbox" name="choices" id="headphone-check" value="head phone">head phone    </div>  </div>

try way


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -