Get name of first empty input field returns "undefined" (jquery) -
i'm running problem here getting attribute name first empty input field. can't figure out, why returns "undefined" every time.
<input type="text" name="test_1" value="not empty"> <input type="text" name="test_2"> <input type="text" name="test_3" value="not empty"> <input type="text" name="test_4"> <script>alert($('input[value=""]').first().attr("name"));</script> thanks alot help.
the element you're looking target has no value property, hence there no elements match [value=""] selector. need include attribute, code works fine:
<input type="text" name="test_1" value="not empty"> <input type="text" name="test_2" value=""> <input type="text" name="test_3" value="not empty"> <input type="text" name="test_4" value=""> if not want amend html (or cannot amend it) need use filter() find elements required value property, available.
var $emptyval = $('input').filter(function() { return !this.value; }); alert($emptyval.first().attr("name"))
Comments
Post a Comment