0

Possible Duplicate:
Can jQuery provide the tag name?

My code:

    $('#tab-menu a,#tab-menu li').click(function(event) {
    event.preventDefault();
});

I need it so that I can execute different code depending on what was clicked so for example

if(element == "li")
//do something
else
//do something else

How would I go about achieving this?

Community
  • 1
  • 1
Ben
  • 5,627
  • 9
  • 35
  • 49

3 Answers3

4

Use .is():

$('#tab-menu a,#tab-menu li').click(function(event) {
    event.preventDefault();

    if ($(this).is("li"))
        // do something
    else
        // do something else
});
Travesty3
  • 14,351
  • 6
  • 61
  • 98
3
$('#tab-menu a,#tab-menu li').click(function(e) {
   if($(e.currentTarget).is('li')
     ...do stuff here
});
supernova
  • 3,814
  • 3
  • 22
  • 37
3

Something like this:

if(this.tagName == "LI")  //note the uppercase

Edit: oh yeah, or you can use is(). But don't give me credit for that if that's what you use.

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67