File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 9393 </ div >
9494
9595 < div id ="aria "> </ div >
96+
97+ < div id ="zIndex100 " style ="z-index: 100; ">
98+ < div id ="zIndexAutoWithParent "> </ div >
99+ </ div >
100+ < div id ="zIndexAutoNoParent "> </ div >
96101</ div >
97102
98103</ body >
Original file line number Diff line number Diff line change @@ -48,4 +48,13 @@ test('focus', function() {
4848 other . focus ( ) ;
4949} ) ;
5050
51+ test ( 'zIndex' , function ( ) {
52+ var el = $ ( '#zIndexAutoWithParent' ) ;
53+ equals ( el . zIndex ( ) , 100 , 'zIndex traverses up to find value' ) ;
54+ equals ( el . zIndex ( 200 ) , el , 'zIndex setter is chainable' ) ;
55+ equals ( el . zIndex ( ) , 200 , 'zIndex setter changed zIndex' ) ;
56+
57+ equals ( $ ( '#zIndexAutoNoParent' ) . zIndex ( ) , 0 , 'zIndex never explicitly set in hierarchy' ) ;
58+ } ) ;
59+
5160} ) ( jQuery ) ;
Original file line number Diff line number Diff line change @@ -184,6 +184,26 @@ $.fn.extend({
184184 }
185185
186186 return ( / f i x e d / ) . test ( this . css ( 'position' ) ) || ! scrollParent . length ? $ ( document ) : scrollParent ;
187+ } ,
188+
189+ zIndex : function ( zIndex ) {
190+ if ( zIndex !== undefined ) {
191+ return this . css ( 'zIndex' , zIndex ) ;
192+ }
193+
194+ var elem = this [ 0 ] ;
195+ while ( elem && elem . style ) {
196+ // IE returns 0 when zIndex is not specified
197+ // other browsers return an empty string
198+ // we ignore the case of nested elements with an explicit value of 0
199+ // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
200+ if ( elem . style . zIndex !== '' && elem . style . zIndex !== 0 ) {
201+ return + elem . style . zIndex ;
202+ }
203+ elem = elem . parentNode ;
204+ }
205+
206+ return 0 ;
187207 }
188208} ) ;
189209
You can’t perform that action at this time.
0 commit comments