diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index bd97356d18..c4cdc16960 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -110,7 +110,7 @@ if (!selector) { selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 } $parent = $(selector) diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 4e52c8485e..3a617692b3 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -61,6 +61,24 @@ $(function () { ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) + test("should test if element has a # before assuming it's a selector", function () { + var dropdownHTML = '' + , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + + ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') + }) + + test("should remove open class if body clicked", function () { var dropdownHTML = '