Reputation: 571
I'm writing short jquery script:
$(document).ready(function (e) {
$("#about, #services, #contact").click(function (e) {
MoveToPage(e);
})
});
function MoveToPage(e) {
var del = e.delegateTarget;
if (del == 'li#about') {
alert('about')
} else {
//dosomething
}
}
The purpose now is to alert which link was clicked. It is not working.Why?
Upvotes: 0
Views: 33
Reputation: 133423
event.delegateTarget
returns the reference to a element. You can use it to evaluate it with a string literal.
You can use .is()
to check the element against a selector.
function MoveToPage(e) {
var del = e.delegateTarget;
if ($(del).is('li#about')) {
alert('about')
} else {
'something'
}
}
You can also use its ID
property
if(e.delegateTarget.id == 'about')
Upvotes: 1
Reputation: 1354
use e.target.id
to get target id which is clicked
here is js you could use:
$("#about, #services, #contact").click(function (e) {
MoveToPage(e);
})
function MoveToPage(e) {
if(e.target.id == 'about')
{
}
else if(e.target.id == 'contact')
{
}
else
{
}
}
here is fiddle for you
http://fiddle.jshell.net/UYMxa/280/
Upvotes: 1