0

i have something like this :

<li>
          <a href="#" id="navId" ng-click="toggleStyle()">

                <i class=" fa fa-navicon">
                </i>
           </a>
</li>
<li>
    <a href="#" id="searchId" ng-click="toggleStyle()">
               <i class="fa fa-search"></i>
    </a>

</li>  

How can i use one function for multi elements like this :

     $scope.toggleStyle = function () {
            if("#navId"){
           //do Stuff
            }
           if("#searchId"){
             //Do somthing else
            }
    }
1
  • use getElementById('navId') instead of ("#navId") Commented Dec 27, 2014 at 7:54

1 Answer 1

2

Just pass whatever parameter you need to the function:

<a href="#" id="navId" ng-click="toggleStyle('navId')">

$scope.toggleStyle = function(param){
  if (param === 'navId') {
    // do stuff
  }
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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