jQuery - Show box/Hide on event doesn't work. why? -


I use this function to show a list (ul) and hide it if a page But click elsewhere It does not appear to be working:

  $ (document) .ready (function () {$ ('# trigger'). Click (function () {$ ('# dropdown (); $ (Document). Click (function () {$ ('# dropdown-option'). Hide ();}); $ ('# dropdown-option'). Function (e) {e.stopPropagation ();});});   

(I'm using Ruby on Rails, and it seems that everything should be under $ (document) .ready (function () {... }}; to make this work.)

This is actually because in the document "#trigger" is happening, it is happening at the same time and take the "stopprofagation" up in the hidden "#tragger" selector, you have to stop the propagation of the event before the document arrives and hide it again. Or will. Click the $ {document} .ready (function () ($ ('# trigger') (function (e) {e.stopprogaction (); $ ('# dropdown-option' ). Show ();}); $ (document). Click (function) {$ ('# dropdown-option'). Hide ();});});

Comments