SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to get the name of an anchor with JQuery?

    Hi,

    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
    PHP Code:
    <div id="faces">
    <
    ul>
      <
    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>
    </
    ul>
    </
    div>

    <
    div id="quotation"> </div
    And the JQuery
    PHP Code:
     $(document).ready(function(){
        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 selectedMath.floorMath.random() * selected.length )];

         $(
    "#quotation").append(randomQuotation);                     
         $(
    "#quotation").slideToggle('slow');
       },function(){
         $(
    "#quotation").hide('slow');
         $(
    "#quotation").empty();
       });
     }); 
    var selected = xxx; I'd like to get churchill or stalin there, correponding to the img hover <a href="#" name="stalin">

    Any idea?
    Thanks

  2. #2
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I found
    PHP Code:
    var selected =  $(this).attr("name"); 
    sorry for the noise

  3. #3
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •