Reputation: 40685
The following snippet is used in conjunction with a jQuery UI autocomplete element (#search
). In Firefox, Chrome, etc. it behaves as expected and always returns true for the selected element. In Internet Explorer 7 it doesn't.
$('mySelector').filter(function() {
if ($(this).text().toLowerCase() == $('#search').val().toLowerCase()) {
return true;
}
});
For any hints about how this behaviour could be caused I will be very thankful!
EDIT: After pasting the nice analyze function by Šime Vidas I run the thing again and here comes the result of the comparison that should return true:
After some more investigation. I seems the comparison returns true (thank god, otherwise I would have needed a shrink). But the filter function return any valid objects. Which it should, if the comparison is true.
EDIT: Turns out I tested only cases where everything was fine. A few entries had double spaces between first and last name which didn't result in a FALSE evaluation in FF and Chrome but did in IE7.
Upvotes: 0
Views: 651
Reputation: 186103
Here:
function analyze( str ) {
var output, i;
output = 'String: ' + str + ' - Length: ' + str.length + '; ';
for ( i = 0; i < str.length; i += 1 ) {
output += str.charCodeAt( i ) + ' ';
}
return output;
}
And then:
alert( analyze( operand1 ) + '\n\n' + analyze( operand2 ) );
Live demo: http://jsfiddle.net/jsZzY/
The alert box will show you all code points of both strings....
Upvotes: 2
Reputation: 27765
Maybe $(this).text()
in IE7 returns some additional chars. For example extra spaces, new lines (\r\n
) etc. Try to output $(this).text()
and $('#search').val()
and visual compare this two strings.
Also you can try to add jQuery.trim
functions, etc. If you rid out from all garbage your code should work.
Upvotes: 1