2

So basically I have a control on my page which when clicked needs to toggle two different elements with two different CSS classes.

I have managed to get it to toggle one of the controls, but not both.

Here is my element:

This is the element that needs to trigger both controls.

<a id="main-menu-toggle" data-toggle="collapse" data-target="#sidebar" class="hidden-xs open"><i class="fa fa-bars"></i></a> 

The first element (That is working):

<div id="sidebar" class="col-lg-2 col-sm-1 collapse" style="min-height: 759px; display: block;"> </div> 

Here is the second element(That i need to add):

For this element i need to trigger the CSS class 'full' when the button is clicked and then not full when its clicked again.

<div id="content" class="col-lg-10 col-sm-11 full"> </div> 

I have tried to do this to the hyperlink control and it still doesn't work:

<a id="main-menu-toggle" data-toggle="collapse,full" data-target="#sidebar,#content" class="hidden-xs open"><i class="fa fa-bars"></i></a> 

Does anyone know how I can get this working using AngularJS?

0

    3 Answers 3

    3

    Try using "ng-class".

    Reference:

    https://stackoverflow.com/a/16529903/5052704

    Hope this helps.

    1
    • I will take a look now as it seems to be the same sort of thing. Thanks :)CommentedSep 4, 2015 at 8:19
    0

    Here is a JSFiddle usign ng-class and ng-click:

    <a id="main-menu-toggle" data-toggle="collapse" data-target="#sidebar" class="hidden-xs open" ng-click="clicked = (clicked) ? false : true"> <i class="fa fa-bars"></i>click </a> <div id="sidebar" class="col-lg-2 col-sm-1 collapse" ng-class="{'full': clicked}" style="min-height: 759px; display: block;"> THEDIV </div> 
    5
    • Nothing happens on the fiddle when i click?CommentedSep 4, 2015 at 8:19
    • Inspect the element you will see it adds and removes the full class EDIT: Added color to class to show something jsfiddle.net/michelem09/smebrtwt/1
      – michelem
      CommentedSep 4, 2015 at 8:19
    • Yeah it shows and hides the red box, but i want it to do two different things at the same time.CommentedSep 4, 2015 at 8:55
    • "when clicked needs to toggle two different elements with two different CSS classes."CommentedSep 4, 2015 at 9:11
    • Still not clear, but try this: jsfiddle.net/michelem09/smebrtwt/2 or explain better your needs.
      – michelem
      CommentedSep 4, 2015 at 9:16
    0

    You can use ngClass for class and ngStyle for style manipulation.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.