1

I want to get the span tag which has the particular attribute value.

This is my html

<ul class="dropdown-menu" id="languagelist">
  <li ng-repeat="(id, langName) in items" ng-click="switchLanguage(id,langName,$event)">
    <span class="glyphicon glyphicon-ok" langAttr={{langName}}> </span>
    <a>{{langName}}</a>
  </li>
</ul>

In my JS file i have $scope.language which has the preferred language. $scope.language might be "English", "Spanish","Japanese","French".

Now in my javascript, I need to get the span tag which has the langAttr(Atrribute) which equals to my $scope.language.

How can i use jquery to get the span tag whose attribute value is equal to the $scope.language

I can get all the span tags like this $("#languagelist span")

How can i filter or find the span tag which has the required attribute ?

If anyone knows any simple way, please do help. Thanks in advance.

Omi
  • 3,954
  • 5
  • 21
  • 41
  • depends on what you want. The tagging of jquery stuff is based on css. If you know your css you can do it easily. e.g. `$("span.glyphicon")` will get you all spans with glyphicon – A. L Jan 11 '17 at 12:47
  • Add angularjs tag, let those people also know this question – Rahul Jan 11 '17 at 12:47
  • 5
    `$('#languagelist span[langAttr="' + $scope.language + '"]')` should do the trick – pistou Jan 11 '17 at 12:50
  • 2
    Possible duplicate of [jQuery how to find an element based on a data-attribute value?](http://stackoverflow.com/questions/4191386/jquery-how-to-find-an-element-based-on-a-data-attribute-value) – pistou Jan 11 '17 at 12:56

0 Answers0