As already noted in the comments, return false will actually exit the cycle "blog", "user", "forum" and, thus, will stop checking the checkboxes if one condition pathname.indexOf true.
You can also add console.log(window.location.pathname); to make sure that this variable contains what you are checking. Perhaps this is a problem with the case?
If you want to know what literals are present in pathname, you can use this:
var isPresent = []; $( ["blog","user","forum"] ).each(function(num,opt) { if ( window.location.pathname.indexOf(opt) != -1 ) { $('#rb-' + opt).attr('checked','checked'); isPresent.push(opt); } });
If you just want to find out if one of the literals is present in the path name:
var isAtLeastOneIsPresent = false; $( ["blog","user","forum"] ).each(function(num,opt) { if ( window.location.pathname.indexOf(opt) != -1 ) { $('#rb-' + opt).attr('checked','checked'); isAtLeastOneIsPresent = true; } });
source share