/    Sign up×
Community /Pin to ProfileBookmark

Why is this jquery AJAX not functioning?

I am trying to load image descriptions from a gallery of images on the same page via AJAX but it keeps directing to a new page from the link url in the image, I dont know why

heres the code in the head:

<script type=”text/javascript” src=”jquery-1.8.1.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){
$(‘.gallery a’).click(function() {
var url=$(this).attr(‘href’);
$(‘#maincontenttext’).load(url + ” #maincontenttext”);
return false;
});
});
</script>

Heres the code for the HTML in the site:

<div id=”gallery”>
<a href=”nexgen.html”><img src=”nexgen.jpg” width=”100″ height=”100″ /></a>
<a href=”silver.html”><img src=”silver-spark.jpg” width=”100″ height=”100″ /></a>
<a href=”crab.html”><img src=”crab.jpg” width=”100″ height=”100″ /></a>
</div>

heres the <divs> what I want to change to reflect each photo description:

<div id=”maincontenttextimage”><img src=”nexgen-lrg.jpg” width=”300″ height=”299″ /></div>
<div id=”maincontenttext”><h1>Photo explanation header placeholder</h1>
<p>Place holder explanation/description of clicked photo from gallery</a>.</p>
</div>

Whats going on? why does it load the silver.html to a new page when I click on the photo not keep it on the same page??????

Plus how can you load 2 <div> from the destination page?

Thanks for any help on this, much appreciated.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @anthonym spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...