javascript - Getting length, id and name of "input" tags -
how length, id , name of input
tags inside div
having class name only?
html:
<div id="division1" class="clonedinput kudd"> <div class="set1"> <label for="eee">name</label> <input id="ee2" type="text" value="" name="ee2"> <input id="ee3" type="text" value="" name="ee3"> </div>
jquery:
$('.set1 > input').attr('id').length; $('.set1 > input').attr('id'); //no output
you can use each
:
$('.set1 input').each(function() { var $this = $(this); // caching var id = $this.attr('id'); var name = $this.attr('name'); var length = $this.val().length; console.log('id: ' + id + ' name: ' + name + ' length: ' + length); });
a generic iterator function, can used seamlessly iterate on both objects , arrays. arrays , array-like objects length property (such function's arguments object) iterated numeric index, 0 length-1. other objects iterated via named properties.
Comments
Post a Comment