Search code examples
javascriptdojoremoveclass

Dojo - removeClass by identifying div using class not working e.g. query('.lb').removeClass('hide');


This works:

query('#lb').removeClass('hide');

But I need to remove the ".hide" class from multiple divs so I tried this:

query('.lb').removeClass('hide');

I'm completely new to Dojo. I'm wondering why I can select the div to remove class from using an ID but not a Class.

Please help!

Heres the HTML i'm using

<div class="lb hide">
        <div class="lbc">test</div>
        <span class="closeBtn">Close</span>
    </div>

<div id="lb" class="hide">
        <div class="lbc">test</div>
        <span class="closeBtn">Close</span>
    </div>

Here's a link to jsFiddle of this: http://jsfiddle.net/7xh003o3/

There are 2 divs, both with the ".hide" class. when the link is clicked, they should both have the ".hide" class removed and appear on screen. But only the one with the ID specified works.


Solution

  • Your fiddle does not have the same code, in your fiddle you have:

    query('.').removeClass('hide');
    

    Which should be:

    query('.lb').removeClass('hide');
    

    The code above should work fine. However, you only have 1 div with the .lb class on it. So you should change your HTML so that both elements have the .lb class, for example:

    <div class="lb hide">
        <div class="lbc">test</div>
        <span class="closeBtn">Close</span>
    </div>
    
    <div id="lb" class="hide">
        <div class="lbc">test</div>
        <span class="closeBtn">Close</span>
    </div>
    

    If you did all that, it should work fine, as you can see in your updated fiddle: http://jsfiddle.net/7xh003o3/2/