I have a light SO. Why can't I bind the click event directly to the bind id? I should have indicated that I also use jQuery Mobile.
<div id="foobarNavbar" data-role="navbar" style="display:none;"> <ul> <li><a id="foo" href="#foo" data-icon="plus">New Event</a></li> <li><a id="bar" href="#bar" data-icon="grid">Events</a></li> </ul> </div>
I am trying to attach a click event to foo. This does not work:
$('#foo').bind('click', function(e) { e.preventDefault(); console.log("You clicked foo! good work"); });
This works, but gives me a click event for foo and bar. Is it not possible to bind the bind identifier or am I making a rookie mistake?
$('#foobarNavbar ul li a').bind('click', function(e) { e.preventDefault(); console.log("You clicked foo! good work"); console.log(e); });
source share