soundasleep / jquery-dropdown

Bootstrap-style dropdowns with some added features and no dependencies.
Other
767 stars 266 forks source link

Dropdown doesn't work with dynamically added menus #19

Closed StupidTook closed 11 years ago

StupidTook commented 11 years ago

It doesn't seem to work when I add the div with class="dropdown dropdown-tip" dynamically (using jQuery). Clicking the link does nothing. I can see my markup being added in DOM at the end of the body tag, and if I add the generated markup statically in the HTML, it works.

Is there a reason for this limitation or a possible workaround?

claviska commented 11 years ago

It should work. Can you provide a fiddle showing the issue? It may be implemented wrong, and it would be easiest to see with a minimal test case.

On Thursday, February 21, 2013 at 11:49 PM, StupidTook wrote:

It doesn't seem to work when I add the div with class="dropdown dropdown-tip" dynamically (using jQuery). Clicking the link does nothing. I can see my markup being added in DOM at the end of the body tag, and if I add the generated markup statically in the HTML, it works. Is there a reason for this limitation or a possible workaround?

— Reply to this email directly or view it on GitHub (https://github.com/claviska/jquery-dropdown/issues/19).

StupidTook commented 11 years ago

EDIT: that fiddle was invalid. This one is better and it works: http://jsfiddle.net/Csjd2/3/ Apparently, I have a problem on my side, so there is no issue with your code. Sorry for the inconveniencce.

Here is a fiddle that demonstrates the issue: http://jsfiddle.net/Csjd2/2/

In fact, I'm adding the trigger dynamically as well, so maybe that's where the problem is. I do use jquery-1.7.2, but it doesn't seem to work with later versions either.

claviska commented 11 years ago

It appears to be something in the way you've implemented it. Here is a more minimal test case: http://jsbin.com/iqoxab/4/edit

As you can see, both the triggers and the dropdown menus are added on the fly without any additional instantiation.