1

this probably has been asked before, but I am unable to find a satisfying answer.

in my HTML markup I have a SPAN element with onclick event, something like

<span onclick='loadDiv()'>Text</span>

When user clicks on the span - a DIV with a higher z-index is absolutely positioned over the span (sort of a dialog window). User then performs an some inside of the DIV and DIV's display is set to 'none', it becomes invisible.

How do I detect from the span point of view when the span becomes visible again? How to implement something akin to "<span onvisible="somefunction()"....

Thanks!

UPDATE: I need this implemented in pure JavaSctipt, max I can use is MS AJAX extentions.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
  • http://stackoverflow.com/questions/4948323/jquery-event-handler-div-becomes-visible-hidden – frenchie Feb 06 '13 at 17:25
  • Forgot to mention - need this in pure JS, not using jQuery, will update the Q. – Yuriy Galanter Feb 06 '13 at 17:29
  • The point is that there's no real way to do in javascript (or jquery). See the answered linked within the questions. All you can do is plug in some code that executes when you're triggering the show/hide events. There's no way to listen to properties changing. – frenchie Feb 06 '13 at 17:31
  • 1
    Technically your span is always visible from a CSS perspective. It just has a lower z-index than your div which is either visible or not. – j08691 Feb 06 '13 at 17:33
  • I suspect you mean "onclick" rather than "onclik" in your code fragment. What is the problem with using JQuery? It's basically just a bunch of javascript libraries. Regardless, your best bet is just to include the "no really, it's visible again" code in the function that sets the div to hidden. – Ben Barden Feb 06 '13 at 17:35
  • Meaning you'd have to detect when the div is hidden, rather than when the span is "visible again". – ajp15243 Feb 06 '13 at 17:36
  • @j08691 true, so perhaps "onshow" would be a more correct terminology – Yuriy Galanter Feb 06 '13 at 17:38
  • @BenBarden Thanks for the correction, fixed the misspelling. Regarding jQuery - company policy, a use of a library need to be really justified, and as of now this would be the only case of its application. And unfortunately DIV can be hidden in many ways, there's no single "Close()" code, so the "visible again" will have to to be added to many places – Yuriy Galanter Feb 06 '13 at 17:40

2 Answers2

0

Modify the function that hides the div again to accept a callback.

function hideThatDiv(callback){
   //whatever code hides your div
   callback.apply({what you'd like `this` to refer to}, [array, of, args])
}
Chris Sobolewski
  • 12,819
  • 12
  • 63
  • 96
0

Actually the solution turned out to be trivial

<span onclick='loadDiv(); var i=setInterval(function(){if (xdivDialog.style.display=="none") {clearInterval(i); handleEvent()}},1000)'>Text</span>

Basically in onClick event I start timer to check regularly if dialog DIV becomes hidden again. Once this is detected I stop timer and handle the event.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136