Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: How to get the style attribute for "position" of an element? [duplicate]

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?
})
like image 609
rahul0789 Avatar asked Dec 08 '25 10:12

rahul0789


2 Answers

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

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

like image 58
Mohammad Adil Avatar answered Dec 10 '25 01:12

Mohammad Adil


Use this, in jQuery:

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

And more:

$(element).offset();
$(element).offset().top;
$(element).offset().left;
like image 31
Praveen Kumar Purushothaman Avatar answered Dec 10 '25 01:12

Praveen Kumar Purushothaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!