In jQuery the click function is like - say the element has an id of 'myDiv':
Code:
$('#myDiv').click(function(){alert('You clicked me!');});
You can select it many ways - say you want all a tags:
Code:
$('a').click(function(){alert('You clicked me!');});
Now the class name could be important. Inside the click function it would be:
this.className
So you could do:
Code:
$('a').click(function(){alert(this.className);});
or even:
Code:
$('a').click(function(){if(this.className == 'active'){
doSomething();
} else {
doSomethingElse();
}
});
In fact, since an element can have more than one class name, you can use jQuery's hasClass. But then you have to make 'this' into a jQuery object, like:
Code:
$('a').click(function(){if($(this).hasClass('active')){
doSomething();
} else {
doSomethingElse();
}
});
If you need more specific help, please explain the specifics, and:
Please post a link to a page on your site that contains the problematic code so we can check it out.
Bookmarks