0

how to I get classes with jquery? I know that $("#nameOfId") gets id, so I assumed $(".nameOfClass") would get class...

The problem is that id is unique while class isnt. I've tried something like $(".nameOfClass")[2].top(), but this doesn't work.

Edit1: Thanks! $(".nameOfClass").position().top worked!

3
  • you can use $(".nameOfClass").eq(2).top() Commented Jul 3, 2014 at 5:58
  • 1
    @ArunPJohny .top() is not a valid jquery mehtod.. Commented Jul 3, 2014 at 5:59
  • @RajaprabhuAravindasamy yes... .position().top Commented Jul 3, 2014 at 5:59

1 Answer 1

1

You can use eq :

$(".nameOfClass").eq(2)

Or,

$(".nameOfClass:eq(2)")
Sign up to request clarification or add additional context in comments.

1 Comment

@user54987 you should use $(".nameOfClass").eq(2).position().top not $(".nameOfClass").eq(2).top()

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.