Reputation: 1417
I have got a problem when trying to identify an INPUT with empty value or which has got just value attribute without ="". Please see below my code.
<form id='form'>
<div class='input-field col s12'>
<input id='title' type='text' value>
<label for='title'>Job Tilte</label>
</div>
<div class='input-field col s12'>
<input type='text' id='company' value='test' />
<label for='company'>Company Name</label>
</div>
<div class='input-field col s12'>
<input type='text' id='telephone' value='' />
<label for='telephone'>Telephone Number</label>
</div>
<div class='input-field col s12'>
<textarea id='description' placeholder='test2'></textarea>
<label for='description'>About you</label>
</div>
<div class='input-field col s12'>
<input type='password' id='password' />
<label for='password'>Your password</label>
</div>
<div class='input-field col s12'>
<input type='password' id='re-password' />
<label for='re-password'>Confirm your password</label>
</div>
<input type='submit' disabled='disabled' value='Update' id='sendbutton' />
And this is my jQuery:
if ($('#form input').val().length !== 0 ) {
$(this).hide();
} else {
$(this).next().addClass('active');
}
Could anybody help me with this issue? Many thanks in advance.
Upvotes: 0
Views: 55
Reputation: 388316
You need
$('#form input').each(function () {
if (this.value.length !== 0) {
$(this).hide();
} else {
$(this).next().addClass('active');
}
})
Upvotes: 1
Reputation: 6031
use below code . each() you can get all the inputs elements inside #form . see DEMO
$(document).ready(function(){
$('#form input').each(function(){
if ($(this).val().length !== 0 ) {
$(this).hide();
} else {
$(this).next().addClass('active');
}
});
});
Upvotes: 1