.has does not return a boolean, so if there are no matches, the returned object has 0 members.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<form>
<div><input id="thebutton" type="button" value="Click Me" /></div>
<div class="test">test div</div>
</form>
<script>
$(document).ready(function() {
$('#thebutton').click(function() {
var par = $(this).parent('form');
if(par.has('.warn').length === 0) {
alert('nothing');
}
});
});
</script>
</body>
</html>
source
share