I just don’t get it.
function init() {
$(document).on('click', '#listFilter .option:not(".darr"), #listSort .option:not(".darr")', function() {
var selected = $(this).data('ajax-link'),
dropDown = $(this).parent().parent(),
filter = '',
sort = '';
if ( dropDown.attr('id') == "weaveListFilter" ) {
filter = selected;
sort = $('#listSort .darr').data('ajax-link');
} else if ( dropDown.attr('id') == "weaveListSort" ) {
filter = $('#listFilter .darr').data('ajax-link');
sort = selected;
}
if ( selected != dropDown.find('.darr').data('ajax-link') )
console.log('why?')
sortList(filter, sort, dropDown.parent());
//console.log('wtf!')
});
}
Without the console.log('why?') the sortList() function is not called!!!
Why does it not get called without this line?
The weirdest thing is, that this “why?” is not even logged in my console. But without it the sortList() function doesn’t execute. The “wtf!” after the function-call would be logged but I don’t get it anyway.
Ideas? Am I dumb or so?
Because your
ifis failing. There are no braces{ }around theifbody, so only the first statement is considered part of theif. By adding theconsole.log, you are making thesortListno longer part of theif.First, put braces around your
if:Then go find out why your
ifclause is failing.