Here is the example:
<div id="outerFrame">
<div class="elementFind">
Username :<input type="text" name="username"/>
Sex :<input type="radio" name="sex" value="Male">Male</input>
</div>
<div class="elementFind">
Username :<input type="text" name="username"/>
Sex :<input type="radio" name="sex" value="Male">Male</input>
</div>
<input type="button" value='Find' id='findElement'/>
</div>
JQuery code:
------------------------
$(document).ready(function(){
$("#findElement").click(function () {
$('#outerFrame .elementFind').each(function() {
var username = $(this).find('input:text[name=username]').val();
var sex = $(this).find('input:radio[name=sex]').val();
alert("Username : [" + username + "] Sex :[" + sex + "]");
});
});
});
The Above code will find the divs with class elementFind using each() function and then will find the elements using find() function.
Check live example here: http://jsfiddle.net/jeetu_verma11/C4FWZ/

0 comments:
Post a Comment