1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

JQuery troubles

Discussion in 'jQuery' started by hermione_dies, Dec 6, 2007.

  1. #1
    I'm trying to have some links load within the same page with jQuery, but it does not seem to differentiate attributes from multiple elements (don't know how to explain it.. heres the code)

    <a href="http://website1/">text</a>
    <a href="http://website2/">text</a>
    <a href="http://website3/">text</a>
    <a href="http://website4/">text</a>
    <a href="http://website5/">text</a>
    HTML:
    
    $("a").click( function () {
      var href = $("a").attr("href");
      $("#content").load(href);
      return false;
    });
    
    Code (markup):
    When I try this it loads the href from the first <a> tag on the page, I want it to use the one that was clicked on
     
    hermione_dies, Dec 6, 2007 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Got a link?
     
    MMJ, Dec 7, 2007 IP
  3. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try changing:
    var href = $("a").attr("href");
    PHP:
    to this:
    var href = $(this).attr("href");
    PHP:
     
    decepti0n, Dec 7, 2007 IP
  4. hermione_dies

    hermione_dies Peon

    Messages:
    309
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Heh.. yeah I tried that the first time I messed around with it but stupidly I was putting quotes around "this" so I thought it didn't work so I just tried putting "a" instead
     
    hermione_dies, Dec 7, 2007 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    Are you sure that shouldn't be
    $('#content').load(href + ' body');
    Code (markup):
     
    joebert, Dec 7, 2007 IP