How to get the name of an anchor with JQuery?


I’m starting to play with JS/JQuery and I don’t know how to get the name af an anchor. I have a list of img faces and when hovering them, I want to display a random quotation

Here is the html

<div id="faces">
  <li><a href="#" name="stalin"><img src="../images/img1.gif" width="50" height="58" /></a></li>
  <li><a href="#" name="churchill"><img src="../images/img2.gif" width="50" height="58" /></a></li>

<div id="quotation"> </div>

And the JQuery

	var churchill = [
	"churchill quotation 1",
	"churchill quotation 2",
	"churchill quotation 3"
	var stalin = [
	"stalin quotation 1",
	"stalin quotation 2",
	"stalin quotation 3"

   $("#faces li a").hover(function(){
	 var selected =  a[name];
	 var randomQuotation = selected[ Math.floor( Math.random() * selected.length )];


var selected = xxx; I’d like to get churchill or stalin there, correponding to the img hover <a href=“#” name=“stalin”>

Any idea?

ok, I found

var selected =  $(this).attr("name");

sorry for the noise

:slight_smile: You’re learning. Glad you’re expanding your range and learning some cool new programming techniques. I started using jQuery a few months ago when Sitepoint came out with jQuery: Novice to Ninja (great book BTW). When you have any other questions, we’ll look forward to hearing about them.