NULL
NULL

Reputation: 1589

ajax get anchor tag name

i have a href like this:

<a href="images/prevFeb-1.jpg" name="day-1" onclick="swap(this); return false;">
  <img src="images/thumbFeb-1.jpg" width="50" height="50" alt="" title="thumbFeb-1.jpg" />
</a>

when the user clicks on a thumbnail, the images get swap. i will like to get the href name upon on click. and i will explode("-",$hrefName) and like to get the value "1"

any ideas many thanks!

Upvotes: 1

Views: 1510

Answers (2)

Brad G.
Brad G.

Reputation: 811

Is this what you're looking for?

function swap(element) {
  var name = element.attributes.getNamedItem("name").value;
  var nameValue = name.split('-')[1];
  // do something with it...
}

More about getNamedItem() here: http://www.w3schools.com/DOM/met_nodemap_getnameditem.asp

Upvotes: 1

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

If you have the hyperlink name fixed then better use substring on the name of your link.

Upvotes: 0

Related Questions