0

So I have this HTML in my code

<button ng-click="goBackDashboard()" class="button back-button buttons  button-clear header-item"><i class="icon ion-ios-arrow-back"></i> 
  <span class="back-text" style="transform: translate3d(0px, 0px, 0px);">
    <span class="default-title hide">Back</span>
    <span class="previous-title">Dashboard</span>
  </span>
</button>

In my angular js controller, I want to be able to find the element with class name "previous-title" and add class "hide" to this element.

I have tried a lot of options, but it doesn't work.

var result = document;
console.log(result.getElementsByClassName('previous-title'))

3 Answers 3

1

Try using jquery:

$('.previous-title').addClass('hide');

Sign up to request clarification or add additional context in comments.

1 Comment

angular.element(document.getElementsByClassName("previous-title")).addClass('hide') if you want to do without jquery
0

You can use ng-hide

    <span ng-hide="your_condition" class="previous-title">Dashboard</span>

If your condition evaluates to true, the span will be hidden. For example, you can set a variable(say myValue) in your controller based on some condition and use it in your span.

Eg:

    <span ng-hide="myValue" class="previous-title">Dashboard</span>

The ngHide directive shows or hides the given HTML element based on the expression provided to the ngHide attribute. The element is shown or hidden by removing or adding the ng-hide CSS class onto the element.

Read more: https://docs.angularjs.org/api/ng/directive/ngHide

1 Comment

Seems valid but only if the 'hide' class @Kingsley adding set display to none. Otherwise ng-hide will not be useful in this case
0

You may take a look at the documentation for ngif https://docs.angularjs.org/api/ng/directive/ngIf and use it in your

    <span> 

element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.