Reputation: 251
I want to check if this input doesn't exist.
I have this condition for checking if the input exist but i want to do the opposite.
if ($('input[name="urlpdfvcmd"]')) {
alert('Input exist.');
}
Thanks.
Upvotes: 1
Views: 1322
Reputation: 340
you can try to do a prev undefined check :
var input = $('input[name="urlpdfvcmd"]');
if( typeof input === 'undefined') {
alert('input not exist')
}
then you can do :
if (!$('input[name="urlpdfvcmd"]').length || $('input[name="urlpdfvcmd"]') === "") {
alert('Input not exist.');
}
Upvotes: 0
Reputation: 875
You can check visibility of that input with "visible" attribute
For example,
if ($('input[name="urlpdfvcmd"]').is(':visible')) {
alert('Input exist.');
}
Upvotes: 0
Reputation: 2090
I know it's been a long time since the question was asked, but I found the check to be clearer like this :
if ($("#A").is('[myattr]')) {
// attribute exists
} else {
// attribute does not exist
}
(As found on this site here)
EDIT
if ($('#A').attr('myattr')) {
// attribute exists
} else {
// attribute does not exist
}
The above will fall into the else
-branch when myattr
exists but is an empty string or "0". If that's a problem you should explicitly test on undefined
:
if ($('#A').attr('myattr') !== undefined) {
// attribute exists
} else {
// attribute does not exist
}
Upvotes: 1
Reputation: 1012
If no length, input does not exist:
if (!$('input[name="urlpdfvcmd"]').length) {
actually existance should be checked with length aswell, not the way you've done it:
if ($('input[name="urlpdfvcmd"]').length) {
Upvotes: 3