I've been poking around in similar questions but nothing has quite matched what I'm trying to do.
Basically, I'm working on a simple chrome extension for fun / to teach myself how scripts interact with chrome. I got a simple script working that will show/hide a given div:
function showHide() {
var e = document.getElementsByClassName("Line");
for ( var i=0, len=e.length; i<len; ++i ){
if(e[i].style.display == 'block')
e[i].style.display = 'none';
else
e[i].style.display = 'block';
}
}
As you'd expect, this hides every instance of "Line" on the page. The next step is to try to hide only divs that contain a certain string. I've been playing around with 'innerHTML.indexOf("Line")' but so far nothing has worked. Most often I'm getting this error: Uncaught TypeError: Cannot read property 'indexOf' of undefined
Intuitively, I'm trying to make something along the lines of:
if (e.innerHTML.indexOf("foo") != -1) { showHide(e); }
But I'm not sure how to integrate that conditional with the showHide() function I have working. I think I'm handling the 'if' statements sloppily, but since I'm pretty rusty with javascript, I'm mostly working by trial and error.
Just posting here in hope I can get some tips/direction.