mostwantedunm
New Member
I find it difficult to understand why (not how) it is necessary to have a class attribute assigned to a div in order to change it's position. For example, the following code wont move the div to 200,200:\[code\]this.m_textLayer = document.createElement( 'div' ); this.m_textLayer.setAttribute( 'id', 'textLayer' ); this.m_textLayer.setAttribute( 'position', 'absolute' ); this.m_textLayer.setAttribute( 'left', '0px' ); this.m_textLayer.setAttribute( 'top', '0px' ); this.m_textLayer.setAttribute( 'width', '300px' ); this.m_textLayer.setAttribute( 'height', '100px' ); this.m_baseLayer.appendChild( this.m_textLayer );$( '#textLayer' ).append( $( 'p' ) ).text( 'test' );// some time later$( '#textLayer' ).css( { left:'200px', top:'200px' } ); \[/code\]but having the 'class' attribute point to a class definition in the css with the same attributes does work as expected:\[code\]this.m_textLayer = document.createElement( 'div' ); this.m_textLayer.setAttribute( 'id', 'textLayer' ); this.m_textLayer.setAttribute( 'class', 'Layer' ); this.m_baseLayer.appendChild( this.m_textLayer );$( '#textLayer' ).append( $( 'p' ) ).text( 'test' );// some time later$( '#textLayer' ).css( { left:'200px', top:'200px' } ); \[/code\]Now, I can speculate on the cause, as it probably has to do with there not being a css style defined when the class attr is not set or something, but could someone explain it to me in detail, or point me to some resource that explains precisely what actually happens here ? (I'm definitely not new to programming, but I am new to css/js/jquery and find it hard to find information on the actual mechanics of js interpretation).