1

I am having a huge issue with an item in the navbar not being able to use the click()

this is my html code:

 <li class="dropdown"> <a class="dropdown-toggle" id="n-btn" href="#" data-toggle="dropdown"> <i class="icon-bullhorn"></i> <span class="badge badge-inverse" id="n-count" style="position: relative; bottom: 2px;">1</span> </a>
      <div class="dropdown-menu alert-dropdown">
        <ul>
        <li class="text-center"><span class="pulser"></span></li>
        </ul>
      </div>
    </li>

and my javascript:

$(window).load(function(){
    $("#n-btn").click(function(e) {
        e.preventDefault();
        alert("test");
    });
});

I tried using $(".dropdown").on("click", "#n-btn",function() { instead but it still doesn't work. If this changes anything I'm using jquery 2.0.0 and Bootstrap 2.3.2

2
  • Why not use DOM Ready instead of load.. How abt the browser you are trying on ? Commented Aug 5, 2013 at 22:55
  • 3
    Any error messages in your console? I tested in jsfiddle and your alert fires. Commented Aug 5, 2013 at 23:00

1 Answer 1

2

Looking at the Bootstrap source for 2.3.2 it looks like it triggers the click.dropdown.data-api event, so instead of:

$("#n-btn").click(function(e) {

use (for Bootstrap 2.x):

$("#n-btn").on('click.dropdown.data-api', function(e) { ...

For Bootstrap 3.x (looking at its version of dropdown.js), try:

$("#n-btn").on('click.bs.dropdown', function(e) { ...
Sign up to request clarification or add additional context in comments.

1 Comment

The event type is still click. The rest is a namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.