Jump to content

jQuery + AJAX + HREF Links


pengu

Recommended Posts

First off, I hope I've posted this in the correct spot.

Apologies if I have not.

 

All I want is a couple of links, lets say 1 2 and 3, they're all href links that lead to some page, but they have an "id" within the HREF.

So when I click them, I want them to load the results into a div, not just load another page.

 

What I have so far..

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
	$("#spLink").click(function(){
		$("#spResult").html(ajax_load).load();
	});
</script>
</head>
<body>

<h1>Test</h1>
<p><a href="test.html" id="spLink">Click</a></p>
<p><a href="test2.html" id="spLink">Click</a></p>
<p><a href="test3.html" id="spLink">Click</a></p>

<div id="spResult">
</div>

</body>
</html>

 

Help!

Link to comment
Share on other sites

Amazing, thought someone would respond by now.

 

Anyways, I've got this far (see code). But it's not loading my pages into the DIV.

Works firefox.

No go Chrome.

 

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
        $('.spLink').click(function(e) {
                e.preventDefault();
                var href = $(this).attr('href');
                $('.spResult').load(href);
			//alert(href);
        });
});

</script>
</head>
<body>

<h1>Test</h1>
<p><a href="./test.html" class="spLink">Click</a></p>
<p><a href="test2.html" class="spLink">Click</a></p>
<p><a href="test3.html">Click</a></p>

<div class="spResult">
</div>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.