0

I'm not a developer, I'm a Googler working through a third-party whatsit service; I know MINIMAL Javascript and am stuck with inline scripting until the sub-boss recovers from his illness and changes my permissions. Everything related I've been able to find references jQuery. Is there a way to do what I need -- hide the elements of a class whose innerhtml contains a certain character -- without the benefit of this fabled jQuery?

Thank you for your patience!

barleycorn
  • 53
  • 5
  • http://stackoverflow.com/questions/5772255/jquery-find-label-by-the-inner-text – GJK Mar 15 '13 at 17:51
  • Mike Brant: Various blindly fumbling Frankensteins, which turned out not to work since they... were all referencing jQuery things, I think. @GJK: jQuery. Can't. I'm not even sure I could do much even if I had more access, to be honest... I seem to recall seeing over sub-boss's shoulder that the only files we could add were images. Gads! – barleycorn Mar 15 '13 at 17:57
  • My apologies, I didn't read your post carefully enough. I think the answer below should help. – GJK Mar 15 '13 at 18:17
  • Added a version to search against an array (a list) of characters. – Whistletoe Mar 15 '13 at 20:27

1 Answers1

1

Here is a variant that hides all elements that contains a specific character:

window.onload = function ()
{
    var character = "x", // The character to search for
        elements = document.body.getElementsByClassName("className");

    for (var i = 0, length = elements.length; i < length; i++)
    {                   
        if (elements[i].innerHTML.indexOf(character) !== -1)
        {
            elements[i].style.display = "none";
        }
    };
}

And a version to search against an array of characters:

window.onload = function ()
{   // The pattern to search for:
    var characters = ["x", "y", "z", "some words", "@&"],
        elements = document.body.getElementsByClassName("className");

    for (var i = 0, length = elements.length; i < length; i++)
    {    
        for (var c in characters)
        {
            if (elements[i].innerHTML.indexOf(characters[c]) !== -1)
            {
                elements[i].style.display = "none";
            }
        };
    };
}
Whistletoe
  • 573
  • 2
  • 10
  • That is actually very helpful, because the site occasionally and (apparently) unpredictably swaps out some characters. (Yeah, I don't even.) This is much neater than trying to address every single variation... – barleycorn Mar 15 '13 at 19:30