0

HTML code (example):

<div class="clsA"><div class="clsA1">TEXT</div></div> <div class="clsB"></div>

I want make DIV which have class-attribute is clsA and their child-elements visible. (both clsA and clsA1 appear). I try

foreach (HtmlElement pageElement in webBrowser1.Document.All)
    {            
        if (pageElement.GetAttribute("className").ToLower() != "clsa")
            pageElement.Style = "display:none";
    }

but everything disappear. Thanks

2
  • That is probably because your IF is always true.
    – Sebastien
    Commented Aug 2, 2013 at 15:22
  • Given your code, it seems to be working perfectly. (You've got an uppercase "A" in your comparison value.) But the code you have will not make anything visible. It will only selectively make things invisible...
    – lc.
    Commented Aug 2, 2013 at 15:23

1 Answer 1

5

The uppercase A in "clsA" will never match a to lower string, so you will set every item on the page to display:none.

3
  • He might want to set the element visible too with else{pageElement.Style = "display:block";}
    – Sebastien
    Commented Aug 2, 2013 at 15:24
  • Yes, it still does not work. I think clsA appear but clsA1 disappear Commented Aug 2, 2013 at 15:33
  • Well this fiddle jsfiddle.net/Spike/DzVxH effectively does what your C# is doing, so I suggest you step through your code in the debugger to work out what is going on.
    – Mike Wade
    Commented Aug 2, 2013 at 15:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.