<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert('hi'+$("input:text").val());
$("input:not(:empty)").val("sdfdf");
});
});
</script>
</head>
<body>
<input type="text" value="aa" />
<input type="text" value="" />
<input type="text" value="aa" />
<button>Click me</button>
</body>
</html>
i am trying to access empty textboxex using jquery and assigning a value hello to it.. but it's not working .
thanks in advance
Just use: $("input:empty"). length == 0; If it's zero, none are empty.
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace). Comments, processing instructions, and CSS content do not affect whether an element is considered empty.
:empty
checks for whether an element has child elements. input
elements cannot have child elements.
If you want to test that the input
element's value is blank:
$(document).ready(function(){
$("button").click(function(){
$("input").filter(function() {
return this.value.length !== 0;
}).val("sdfdf");
});
});
There we get all of the input
elements, and then filter it so only the ones whose value
property isn't ""
are included.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With