3

What is the proper mark-up in jQuery (or JavaScript) to get the style attribute "position" for an element in the DOM?

Example:

HTML

<div id="Parent">
    Parent Element
    <ul class="child">
        <li>
            <p>inner child elements</p>
        </li>
    </ul>
</div>

CSS

#Parent {
    position: relative;
}
.child {
    position: absolute;
}

JavaScript:

$(function() {
    //  What to type here to get "style attribute position" of say #Parent?
})
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
rahul0789
  • 327
  • 1
  • 3
  • 7

2 Answers2

9
$('#someElementID').css('position');

http://api.jquery.com/css/

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
2

Use this, in jQuery:

$(element).css("position");

And more:

$(element).offset();
$(element).offset().top;
$(element).offset().left;
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252