javascript - Get list element with JQuery according to its value -


assume have following list:

    <ul class="pagination pagination-sm">         <li><a href="#">ru</a></li>         <li><a href="#">ro</a></li>     </ul> 

with jquery, want select list element has value ru. how can achieve this?

alternative solution in 1 line ;)

var ru = $("ul li a:contains('ru')").text();    // demonstration purposes    $('.tron').text(ru);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>  <ul class="pagination pagination-sm">          <li><a href="#">ru</a></li>          <li><a href="#">ro</a></li>      </ul>    <!-- demonstration purposes -->  <h1 class="tron"></h1> 


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -