0

I am trying to create a custom jquery selector to return the bool of css("visibility") == "inherit" but it doesn't seem to be working. Below is the code...

$.expr[":"].crazyvisible = function(a) {
    var elem = $(a);
    return (elem.css("visibility") == "inherit");
};

This is the code I'm using the selector in (i've also tried live)...

$(document).ready(function() {
    $("span#Request1_multiconditionvalidator2").delegate(":crazyvisible","attachErrorMessage", function() {
        ...
    }
}
bflemi3
  • 6,698
  • 20
  • 88
  • 155

1 Answers1

1

There's nothing wrong with your selector or your .delegate() call as far as I can tell. The problem is that the .css() function returns the computed style of an element, so you will never get 'inherit' as the value because that's then computed to whatever style an element's parent has instead.

You can find more info on checking inherited CSS properties using jQuery in this question — in short, though, it's not easy to do so.

EDIT: if you only need to know if an element isn't 'hidden', whether inherited or not, you can just do this:

$.expr[":"].crazyvisible = function(a) {
    var elem = $(a);
    return elem.css("visibility") != "hidden";
};
Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • for some reason this isn't working. I put a watch in firebug for $("span#Request1_multiconditionvalidator2").css("visibility") and it equaled hidden. then I met the condition to unhide the span and it equaled inherit – bflemi3 Aug 31 '11 at 19:09
  • just an update. I tried this in the firebug watch... $("span#Request1_multiconditionvalidator2:crazyvisible").attr("id") and got "Syntax error, unrecognized expression: Syntax error, unrecognized expression: visibility" – bflemi3 Aug 31 '11 at 19:31
  • I'm going to give you the answer because under normal circumstances this would work perfectly. I think I'm having issues because another script that I don't have access to is causing issues with my code. Thanks for your help. – bflemi3 Sep 02 '11 at 13:20
  • No problem. Here's hoping you get it sorted! – BoltClock Sep 02 '11 at 13:21