i don’t why but the not() method of jquery return the same value for two differents tests that are exclusive.
Look:
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script language="javascript">
$(function() {
$(':button, :submit').filter(function() {
$('#result').append('tag = ' + $(this)[0].tagName + "<br />");
$('#result').append('.not(\':submit\').length = ' + $(this).not(':submit').length + "<br />");
$('#result').append('.not(\':button\').length = ' + $(this).not(':button').length + "<br />");
$('#result').append('.is(\':button\') = ' + $(this).is(':button') + "<br /><br />");
});
});
</script>
<button>Btn1</button>
<input type="button" value="Btn2" />
<input type="submit" />
<div id="result">
</div>
Here are the results :
tag = BUTTON
.not(‘:submit’).length = 0
.not(‘:button’).length = 0
.is(‘:button’) = true
tag = INPUT
.not(‘:submit’).length = 1
.not(‘:button’).length = 0
.is(‘:button’) = true
tag = INPUT
.not(‘:submit’).length = 0
.not(‘:button’).length = 1
.is(‘:button’) = false
Found a bug ?
I assume you are confused by
Your assumption is wrong, your tests are not exclusive. The jQuery documentation states:
Now, it happens to be that
buttonelements have atypeattribute and the default value issubmit.So jQuery returns the correct results.
not(:button).lengthreturns0because we are dealing with abuttonelements.not(:submit).lengthreturns0because that button element as atypeattribute with valuesubmit.