1

I have a series of containers containing map data and links. Im using jquery to cycle through those containers to get certain data. In this situation im trying to get an attribute of a link.

I use the following jquery to get all of the html of each container.

 $(document).ready(function () {
    $(".map_container").each(function () {
        alert($(this).find(".map_content").html());
    });
 });

This creates an alert with a few lines of html, the line im concerned with is below.

 <a class="map_link" value="67" location="home"> Visit home </a>

How could I alert value of the location attribute. So in this case "home".

Something like

$(this).find(".map_content").attr("location");

or if possible just find the location without having to find the map_content div first. so

$(this).find.attr("location"); 

or

$(this).find("a").attr("location"); 

what would be the correct way to get the location attribue of the map_link link?

Thanks for any help

Sam Healey
  • 666
  • 2
  • 8
  • 22

2 Answers2

0
$(this).find(".map_content").attr("location");

would be incorrect, since $('.map_content') would have no child with class map_content, hence you cannot find that.

Second option is wrong, since usage of find is wrong.

$(this).find("a").attr("location"); 

should be good.

JSFIDDLE DEMO

Optimus Prime
  • 6,817
  • 5
  • 32
  • 60
0

You can use this like

$(document).ready(function () {
    $(".map_link").each(function () {
        alert($(this).attr("location"));
    });
 });

Here is the JSFIDDLE

Vignesh Pichamani
  • 7,950
  • 22
  • 77
  • 115