I have an unordered list with some links. Some links have a class "A" others have a class "B". I'd like to call a jQuery function depending on which class is clicked, but I don't know how to do this.
5 Answers
$('.yourClass').click(function(e){
//do something here
});
7 Comments
Raoul
Example:
<li><b><a href="#" class="Page">test</a></b></li> then using $(document).ready(function(){ $('.Page').click(function(e){ alert('Clicked'); }); }); doesn't do anything, no errors if firebug but no alert.ave4496
take a look at this: jsfiddle.net/BdwTJ . The example you provided works. Maybe this is not your problem. Did you load query correctly?
Raoul
jQuery is loaded correctly, it's being used for other things on the page without any problems. I made a new test. The list was being generated by the jquery tmpl plugin. If I create a list with identical properties by hand on the same page the click function works fine. I guess this is down to the rendering not working with my tmpl generated list.
ave4496
try defining the click event after your list has been loaded
Raoul
I've tried this also by having the click event at the in script tags below everything else, but before the closing html tag. Here is a proof of concept example of the problem stackoverflow.com/questions/5962556/…
|