textContent.indexOf("text") > -1) dont find everything

in Script development
Subscribe to textContent.indexOf("text") > -1) dont find everything 5 posts, 3 voices



spyvingen User
ChromeWindows

I now use this code to search for text in a table


for (var i=0; i<rowset.length;>
if (rowset[i].children[0].textContent.indexOf("TEXT") > -1) rowset[i].style.backgroundColor = color01;
}

But this code seems to not either stop the script or don't find the row in some cases.
I don't know how to see logs about what happens but i think it stops the execution of the script cus some other searches don't get through after this.

The search string i use includes letters space and "-" ">" and dot (example "Text -> text. Text") is there some of these i have to escape to get it working or is there another way of searching?
If i need to escape pls let me know how.

Ty all for reading

 
mike cupcake Scriptwright
FirefoxMacintosh

the Web Developer extension's Error Console would help you debug: https://addons.mozilla.org/en-US/firefox/addon/...
or lookup Firebug if you want a full inspection+debugging tool.

Using the console.log() command in your script lets you log specific variables (or just a status textstring so you know the code has executed to that point)

your first line looks wrong but I see it's just got mangled by posting it here.

 
Jefferson Scher Scriptwright
FirefoxWindows

Your loop didn't post correctly. The textContent should be the content of the cell stripped of tags. If you look at the source of the page, can you see anything peculiar about the missing matches? Please note that JavaScript is case sensitive. If you need a case insensitive search, you could do this:

for (var i=0; i<rowset.length; i++){
 if (rowset[i].cells[0].textContent.toUpperCase().indexOf("TEXT") > -1) rowset[i].style.backgroundColor = color01;
}

 
spyvingen User
ChromeWindows

[10:07:57.408] Expected ':' but found '.'. Declaration dropped. @ http://domain.org/webpub/cgstilmall.css:254

Could this be whats bugging my script. Looks like it works for now without any change. But could i replace . with something to get this script execute without errors? Or is this just an error from css?

 
Jefferson Scher Scriptwright
FirefoxWindows

"Declaration dropped" definitely refers to a CSS warning.