getStyle z-index

103 views
Skip to first unread message

kstubs

unread,
Aug 12, 2011, 12:36:13 PM8/12/11
to prototype-s...@googlegroups.com
When calling getStyle, do you call out the style by camel-case?  So:

myElement.getStyle('zIndex');

-or-

myElement.getStyle('z-index');

Also, if the style has not been defined, as in z-index for example, you can expect a null return type, but aren't there default values that might be returned?

Karl..

shubhojoy

unread,
Aug 12, 2011, 9:01:42 PM8/12/11
to Prototype & script.aculo.us
You use the camel case to get the z-index like so:

myElementZ = $(myElement).getStyle(zIndex);

Also, sometimes it can be a pain to realize that myElementZ is not an
integer. So, a parseInt(myElementZ) should guarantee that it can be
used for further calculations.

Not sure why you want to obtain any default values. IMHO, default
values can be notorious because of different browsers so the best way
to do things would be to always put your own value to it if it's
absolutely necessary.

One thing I frequently do is use a statement to get the topmost layer
z-index in the following way:
topZ_current = $$("div").invoke("getStyle", "zIndex").max();

Again, parseInt is required if you need the value for calculations,
which is probably the reason you did get it. Add 1 to it and place
your new element on top of the topmost layer...

Hope this helps you.

kstubs

unread,
Aug 13, 2011, 11:50:03 PM8/13/11
to prototype-s...@googlegroups.com
Thanks for the feedback.  I was just curious if different properties of an element have a default value or not.  I like the use of max().

Karl..
Reply all
Reply to author
Forward
0 new messages