JavaScript How can I fetch value from anchor element nested in li element fetch value from dictionary in python,fetch value from map

I have this ul li html element:

 <ul id="langMenu" class="top-links list-inline">
                        <li>
                            <a class="dropdown-toggle no-text-underline" data-toggle="dropdown" target='_blank' href="#"><img class="flag-lang" src="~/assets/images/flags/no.png" width="16" height="11" alt="lang" />NORSK</a>
                            <ul class="dropdown-langs dropdown-menu">
                                <li><a value="no" tabindex="-1"><img class="flag-lang" src="~/assets/images/flags/no.png" width="16" height="11" alt="lang" />NORSK</a></li>
                                <li class="divider"></li>
                                <li><a value="us" tabindex="-1"><img class="flag-lang" src="/assets/images/flags/us.png" width="16" height="11" alt="lang" /> ENGLISH</a></li>
                                <li><a value="de" tabindex="-1"><img class="flag-lang" src="/assets/images/flags/de.png" width="16" height="11" alt="lang" /> GERMAN</a></li>

                            </ul>
                        </li>
                    </ul>

when I implement selection I need to fecth value of the selected element.

For example:

If user selected English I need to get en value from anchor. If user selected Norsk I need to get no value from anchor.

How can I fetch value from anchor element nested in li element using jquery?

Answer:1

This code will take the value of your link but only on links that is inside your langMenu nested ul li

$('#langMenu ul li').click(function() {
  console.log($(this).find('a').attr("value"))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="langMenu" class="top-links list-inline">
  <li>
    <a class="dropdown-toggle no-text-underline" data-toggle="dropdown" target='_blank' href="#"><img class="flag-lang" src="~/assets/images/flags/no.png" width="16" height="11" alt="lang" />NORSK</a>
    <ul class="dropdown-langs dropdown-menu">
      <li>
        <a value="no" tabindex="-1"><img class="flag-lang" src="~/assets/images/flags/no.png" width="16" height="11" alt="lang" />NORSK</a>
      </li>
      <li class="divider"></li>
      <li>
        <a value="us" tabindex="-1"><img class="flag-lang" src="/assets/images/flags/us.png" width="16" height="11" alt="lang" /> ENGLISH</a>
      </li>
      <li>
        <a value="de" tabindex="-1"><img class="flag-lang" src="/assets/images/flags/de.png" width="16" height="11" alt="lang" /> GERMAN</a>
      </li>

    </ul>
  </li>
</ul>
Answer:2

as i can understand, you can do like this:

$('a').click(function(event){
console.log($this).attr('value');
event.preventDefault();
});
Answer:3

I have 2 buttons yes and no, and simply I am toggling them. <!DOCTYPE html> <html> <head> <title>Demo Project</title> </head> <...

I have 2 buttons yes and no, and simply I am toggling them. <!DOCTYPE html> <html> <head> <title>Demo Project</title> </head> <...

  1. radio button checked by default
  2. radio button checked html
  3. radio button checked jquery
  4. radio button checked not working
  5. radio button checked attribute
  6. radio button checked css
  7. radio button checked event
  8. radio button checked value
  9. radio button checked c#
  10. radio button checked angular
  11. radio button checked react
  12. radio button checked value jquery
  13. radio button checked false
  14. radio button checked event angular 6
  15. radio button checked in javascript
  16. radio button checked or not in jquery
  17. radio button checked event jquery
  18. radio button checked android
  19. radio button checked by default html
  20. radio button checked php

I have a trie (also called a prefix tree). Given a prefix, I want to get a list of ten words that start with the prefix. The thing that's unique about this problem is that I only want 10 of the ...

I have a trie (also called a prefix tree). Given a prefix, I want to get a list of ten words that start with the prefix. The thing that's unique about this problem is that I only want 10 of the ...

I'm trying to get data from a server in my AngularJS app, using $http.get. But when I execute the request, it seems to get cancelled by something. It happens with every link I use. Local files are ...

I'm trying to get data from a server in my AngularJS app, using $http.get. But when I execute the request, it seems to get cancelled by something. It happens with every link I use. Local files are ...

  1. angularjs http request
  2. angularjs http request example
  3. angularjs http request timeout
  4. angularjs http request default timeout
  5. angularjs http request headers
  6. angularjs http request in loop
  7. angularjs http request interceptor example
  8. angularjs http request interceptor
  9. angularjs http request progress bar
  10. angularjs http request error handling
  11. angularjs http request synchronous
  12. angularjs http request parameters
  13. angularjs http request cors
  14. angularjs http request body
  15. angularjs http request json
  16. angularjs http request multipart/form-data
  17. angularjs http request cross domain
  18. angularjs http request method options
  19. angularjs http request content type
  20. angularjs http request form data

So I can create a whole bunch of empty objects that are independent with my code below. Is there a better way to do this? Or is this the only method? var array = []; for (let i = 0; i < 5; ...

So I can create a whole bunch of empty objects that are independent with my code below. Is there a better way to do this? Or is this the only method? var array = []; for (let i = 0; i < 5; ...