After submitting a search query to a php file I try to go back to the previous page in order to test if all is well e.g.
> search.php [goto] > results.php [backto] > search.php
I have this bit of JQuery code which checks if a checkbox is checked upon landing on the search.php file
$(document).ready(function(){
if($("input[name=filterSite]").not(':checked')){
alert("not checked");
}
});
It always returns not checked even though the html markup is always set to the following
<input name="filterSite" type="checkbox" id="filterSite" checked="checked" />
What could be causing this problem? and how do I fix it?
Most jQuery methods return objects, not boolean values (so that you can chain methods to get to the desired result). The return value of .not() will always be an object (which will evaluate to true in the above condition).
What you want is one of these two:
OR:
.size() will return the number of elements which are currently part of the selector
.is() returns boolean, evaluating whether or not the elements in the selector match the given condition