function test() {
var foo = [];
$('#tree table').each(function(i, table) {
foo[i] = $(table).text().trim();
});
var ch = 'G';
for (j = 0; j <= 12; j++) {
if (foo[j] ^= ch) {
alert(foo[j]);
}
}
}
[foo[j] ^= ch] startsWith selector isn’t working in the above code. What do I have to do to get the expected result?
The
starts-withselector is for use within jQuery selectors when selecting DOM elements based on the value of an attribute.This does not work within regular javascript
if()statements.Try this instead:
This will check
foo[j]to see if the index position (if any) of the value of thechvariable is position0(in other words, at the beginning).EDIT:
Another alternative would be to specifically test the first character against
ch. But this will only work for testing one character. Ifchcontains more than one, it will fail.