I have a two strings, word and text. text is generated by looking at the node values of text nodes in a table. word is a string to find in text.
However, in this situation, In Google Chrome 5.0.375.125 (Official Build 53311) beta, and Firefox 3.6.8, I get the following output:
console.log(text)
st. text text text text text text text text text text text text text text text text text text text text text text text text text text look look text text text text text text text text text text text text text text text text text text text text text text text text text text text text more more more
console.log(word)
look look text text text text text text text text text text text text text text text text text text text text text text text text text text text text more more more
"st. text text text text text text text text text text text text text text text text text text text text text text text text text text look look text text text text text text text text text text text text text text text text text text text text text text text text text text text text more more more".search("look look text text text text text text text text text text text text text text text text text text text text text text text text text text text text more more more")
134
text.search(word)
-1
If I run this same code outside of a table, it works fine.
Why am I getting an inconsistent result?
EDIT: Here is the DOM through which the code looks through, when this error happens:
`<table class="ml-table"><tbody><tr><td><div class="ml-par">Test<br></div></td><td><div class="ml-par"><br></div></td><td><div class="ml-par"><br></div></td></tr><tr><td><div class="ml-par"><br></div></td><td><div class="ml-par">Test<br></div></td><td><div class="ml-par"><br></div></td></tr><tr><td><div class="ml-par"><br></div></td><td><div class="ml-par"><br></div></td><td><div class="ml-par">Test. Text text text text text text text text text text text text text text text text text text text text text text text text text text look look text text text text text text text text text text text text text text text text text text text text text text text text text text text text more more more<br></div></td></tr></tbody></table>`
Here is an example of DOM where it works:
`<div class="ml-par">Test. Text text text text text text text text text text text text text text text text text text text text text text text text text text look look text text text text text text text text text text text text text text text text text text text text text text text text text text text text more more more<span></span></span><br></div>`
Here is the code that does the actual generating of the text variable:
_getTextNodeArrayText : function (nodes) {
var string = "";
var secondString = "";
$.each(nodes, function(index, value) {
secondString = value[0].nodeValue.replace(/\u00A0/g, ' ');
string = string + secondString;
});
return string;
},
The word variable also has its no-break spaces replaced with normal spaces.