1

I have a search bar and when on blur the div gets hidden. However when I click a specific div I don't want to execute the on blur function. I mean only for the specific point when the user clicks there, I don't want on blur to execute but for other cases I want it to work. What should I do?


I am editting this message for jfriend00:

I guess I didn't express myself clearly. I wan to do this situation on the fly. I mean when the user click location_event class I dont want blur execute. The hard thing is onblur execute before onclick, so I have to do something in onblur function but I dont know what to do?

I think, I should get the event target (this clicked div class) in blur function, but i dont know how?

nightwing
  • 11
  • 3
  • Now that you've edited your question, it looks to me like a duplicate of [how to prevent blur() running when clicking a link in jQuery?](http://stackoverflow.com/questions/7621711/how-to-prevent-blur-running-when-clicking-a-link-in-jquery) – jfriend00 Aug 04 '12 at 02:16

1 Answers1

4

Put a global flag in your blur handler and you can then set or unset that flag to determine whether your blur handler should do anything or not.

Working example: http://jsfiddle.net/jfriend00/BqmZr/

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Do you mean a flag as a property *of* the handler function itself? It wouldn't be a problem to just bind/unbind the blur handler each time... – Šime Vidas Aug 04 '12 at 01:33
  • @ŠimeVidas - there are lots of ways to implement the flag. It could be a global variable, a closure variable, a `.data()` property, a property of a function, etc... Often it's not so simple to bind/unbind because the code that wants to change the state is separate from the code that knows how to bind the right event handler, but it could also be done that way if convenient. – jfriend00 Aug 04 '12 at 01:38