I have a form where a user is supposed to select predefined data add new data in an input field named xxx and then he/she can proceed further.
When predefined data is selected, a new hidden input is created
$('.selectlists').append('<input type="hidden" name="select" value="1" />')
I have a function which checks if the hidden field exists and if input xxx has any value
function checkAll(){
if( $("input[name*='select']") ){
alert('ok');
}
else{
if ( $("input[name*='xxx']").val() != '') {
alert('ok');
}
}
}
The function is working fine. But if I create the hidden input and then remove it with jQuery’s function remove(), my function checkAll() is showing that the hidden input still exists.
should check for the length …
JQuery returns an array of matching elements.