-2

Is there a way to 'undo' functions in jQuery? Let me explain.. I have a function which recreates exactly the select html tag. As you know with a select tag, clicking on a list item select that one, when clicking outside the select tag, the whole dropdown list closes. The selecting works fine, but the closing isn't. I though this would work with the event.stopPropagation() event object but it doesn't. Is there any other solution for this?

Demo: http://jsfiddle.net/cmAtc/

user1901096
  • 247
  • 4
  • 15
  • 1
    Not as such, no -- you have to build your own "undo" functions. – Blazemonger Jan 28 '13 at 14:19
  • Is there a particular reason you don't just use a ` – jbabey Jan 28 '13 at 14:19
  • @jbabey CSS styling, possibly. – Blazemonger Jan 28 '13 at 14:20
  • 1
    If you're working with a plugin, it should have a destroy method that restores it to the original markup. – jrummell Jan 28 '13 at 14:20
  • @jbabey clicking the list opens another div with new options etc.. For this very project a unordered list is better, although i would also just use the – user1901096 Jan 28 '13 at 14:22

1 Answers1

1

There is really nothing like what you are asking for that is built into jQuery natively. You have to do it on your own.

My suggestion would be to bind to the document:

$(document).on('click', function () {
    $(".dropdownlist li").parent().children(":not(.selected)").hide();
});

You already have the stopPropagation that would prevent this from being triggered when you click the list too.

http://jsfiddle.net/cmAtc/1/

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405