tags:

views:

55

answers:

2

I need to set some special style for an element if some other element is visible (which is indicated by a special css class and can change dynamically). I need to do this because the page rendering and it's behavior is fully controlled by some framework's code and I don't want to change it. I can put any content anywhere in the body of the page. Is there a non-hacking way to do it?

My only idea was to use some plug-in like "watch" for jquery, but it's very ugly.

A: 

I'm guessing You can override element's method prototype to fire desired one when changing css style?

alexander
Can you provide some example? I don't know how to "override element's method prototype"...
calavera.info
+1  A: 

try using the properychange/attributemodified event

  $("object-in-question").bind("DOMAttrModified propertychange", function(e) {
    if($(this).is(":visible")).... etc
  });

http://jsbin.com/abece4

stereofrog
Doesn't work in Chrome 4, Chrome 5 (so presumably in no WebKit browser), IE 6 and IE 7.
Pekka
@Pekka, it does work in all IEs.
stereofrog
@stereofrog your snippet didn't work for me in 6 and 7. I'll re-check later.
Pekka
@stereofrog it doesn't work for me in 6 and 7, but this can be down to IETester. Sorry.
Pekka
@Pekka, onpropertychange is documented and known to work in all IEs from 5.5 IIRC
stereofrog
@stereofrog yup, true.
Pekka
Thanks, this is what the latest versions of watch plugin for jquery do (with the periodic timer driven failover in case of chrome and others).
calavera.info