2

I have a div structure as below.

    <div class="class1">

        <a href="http://google.com" target="_blank" class="class2">

        </a>

   </div>

So on focus of href, may I know how we can add a class to div(that is parent of href) using angular js

Thanks, Balaji

1 Answer 1

4

You need to use two directives. data-ng-focus and data-ng-class

<div class="class1" data-ng-class="{'className' : applyClass == true}">

   <a href="http://google.com" target="_blank" class="class2" data-ng-focus="applyClass=true"></a>

</div>

Please don't forget to mention this varibale false in your controller first.

$scope.applyClass = false;

Or you can even use

<div class="class1" data-ng-init="applyClass = false" data-ng-class="{'className' : applyClass == true}">
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks for you answer Vineet, let me check :)

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.