Ollicca Mindstorm
Ollicca Mindstorm

Reputation: 608

Get element's top property from its inline css

I have the following element with its inline css:

<div class="collection" style="top: -482px;"></div>

How can I get the top value that is set with inline css?

I know of offset but that returns the coordinates relative to the document as far as I know, what I need is the element's specified top position.

Upvotes: 0

Views: 328

Answers (3)

Raja Sekar
Raja Sekar

Reputation: 2130

Var x=$(".collection").position(); alert("Top: " + x.top + " Left: " + x.left);

This will give exact position values.

Upvotes: 0

Steven Web
Steven Web

Reputation: 1961

A nother aproach:

  var styles = $('.collection').attr('style').split(';');
  alert(styles[0]);

I'm creating an array of the inline styles and alert the first one.

UPDATE:

DEMO

Upvotes: 1

flowstoneknight
flowstoneknight

Reputation: 1236

To get an element's CSS property, use the jQuery method .css(). Here's a fiddle to demonstrate its use.

Upvotes: 2

Related Questions