Auto Loans - Xbox Mod Chip - WesternUnion - Loans - Internet Advertising

PDA

View Full Version : JQuery troubles


hermione_dies
Dec 6th 2007, 7:25 pm
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>

$("a").click( function () {
var href = $("a").attr("href");
$("#content").load(href);
return false;
});


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

MMJ
Dec 7th 2007, 10:32 am
Got a link?

decepti0n
Dec 7th 2007, 12:25 pm
try changing:
var href = $("a").attr("href");
to this:
var href = $(this).attr("href");

hermione_dies
Dec 7th 2007, 4:43 pm
try changing:
var href = $("a").attr("href");
to this:
var href = $(this).attr("href");

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

joebert
Dec 7th 2007, 7:27 pm
Are you sure that shouldn't be
$('#content').load(href + ' body');