Hi,
This is not a Twitter Bootstrap issue. It is a basic JavaScript question but
i'll answer it and it might grab your attention to learn more about basics by
yourself.
Each elements in the browsers broadcast events. Mouse in, mouseout, click,
mousedown, scrollup (see [0]) and you can grab and act on them [1]
$('body').on('click', 'body > .navbar', function(event){
$(event).preventDefault(); window.location = 'foo.html'; });
This code assumes you put the navbar as a direct child of the body ( see '>' in
[2] section 2. selectors ).
Take note that I do not attach 'on' on the navbar itself but on the body so you
now know its possible. In fact I personally prefer attach event on a known
parent of a HTML pattern in more complex situations...but it is always safe to
assume you will have a parent 'body' tag.
As you should know, the term 'click' is only an event name triggered when yoh
click the element described by the selector. This means that you can create
ANY event you might want...even namespace them (e.g. 'myapp.saidyo') and play
with event bubbling.
Read what Douglas Crockford has to say about JavaScript Events ;)
Make sure you put that code in a $(document).readyfunction(){}); as it will
wait to attach the event 'on' when the full DOM is loaded.
Also, in a situation of an event can happen only once (here, the click on .nav
changes the location) you could use 'one' instead of 'on'.
I hope I gave you enough insight to get started learning.
[0]: http://www.w3.org/TR/DOM-Level-3-Events/#events-mouseevent-event-order
[1]:http://api.jquery.com/on/
[2]:http://www.w3.org/TR/css3-selectors/
Regards,
Renoir Boulanger | Developer operations engineer
W3C | Web Platform Project
https://renoirboulanger.com/ ✪ @renoirb
~
--
You received this message because you are subscribed to the Google Groups
"twitter-bootstrap" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.