If you're using just div
s, using a className
would be convenient and valid. Like this:
<div class="menu">
<div class="latest">Latest</div>
<div class="oldest">Oldest</div>
</div>
...
function divClickHandler(event) {
var div = event.target;
if (div.className == 'latest')
// load latest
else if (div.className == 'oldest')
// load oldest
}
If you're using html5, an even better solution would be using custom data- attributes; like this:
<div class="menu">
<div data-type="latest">Latest</div>
<div data-type="oldest">Oldest</div>
</div>
The most elegant solution would be using a
tags instead of the div
s and intercept their clicks:
<div class="menu">
<a href="?whatever">Latest</a>
<a href="?barfoo">Oldest</a>
</div>
...
function aClickHandler(event) {
var a = event.target;
// do your ajax call using a.href
return false;
}