0

How can I get inline-css right value of second child of the div #one using jQuery.

<li id="one">
  <h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia, velit!</h2>
  <div style="width: 1425px; height: 1080px; right: 55px; top: 0px;">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo dolorum reprehenderit natus consequuntur magnam exercitationem nemo similique labore laudantium iure libero at minus, aperiam sequi. Officiis rem optio, quasi perspiciatis facilis est. Aliquam quisquam atque ea earum odit, itaque, excepturi accusamus quasi neque voluptatibus ipsum error qui facilis magnam eveniet.</p>
  </div>
</li>

2
  • Your div only has 1 child. Commented Oct 29, 2015 at 20:09
  • Oh, I'm trying to get the value of right: 55px from the div. Commented Oct 29, 2015 at 20:11

2 Answers 2

3

Check out this documentation: http://api.jquery.com/css/ You can get inline css for 'right' like this:

$('div').css('right')

Or if you want to be more specific:

$('#one div').css('right')

if you want the first div:

$('#one div').first().css('right');

// you can also do this
$('#one div:first').css('right');
Sign up to request clarification or add additional context in comments.

4 Comments

I need to reach the div through parent ID, I have multiple divs with right attributes.
is the div you want to access always the first div inside the li ?
Is #001 a valid CSS selector? It begins with a number.
Well strictly speaking I think an id attribute has to begin with [a-z] or [A-Z] for html 4. In html 5 this is valid.
1
$('#one div').css('right');

or

$('#one').find('div').css('right');

You can also add a class or and id for the div or access through a selector child with jquery.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.