I have a series of links, each with their own id:
<li><a id="about" href="#">About</a></li>
<li><a id="call-us" href="#">Contact us</a></li>
<li><a id="home" href="#">Head on home</a></li>
Instead of writing a series of statements like this:
$(document).ready(function(){
$("a.about").click(function(event){
$("#content").load("/data.html #about");
});
$("a.call-us").click(function(event){
$("#content").load("/data.html #call-us");
});
});
Is there a way to abstract out the fact that when I click on a link with the class "ajax", I take its #ID
, look at .data.html
, and pull from data.html
the div with the id #ID
?
(I understand right now this doesn't specify the class, but let's just say I have 5 anchors like
<a href="#" class="ajax" id="UNIQUE-ID">Anchor Text</a>
It'd certainly make for code that was easier to maintain. Any input would be grand.