0

try the following:

add two divs to a page with the same class name. add two elements within each div: for argument's sake paragraphs. make the text color of the first paragraph of each div red.

why can't i figure out how to do this relatively simple task without having to use id's?

1
  • I think no one can answer this question. How should we know why you can't figure it out? We, or at least I, don't even know you. ( ;) ) Commented Jun 24, 2010 at 10:52

1 Answer 1

4

You can do it like this in jQuery (:first-child selector):

$(".myClass > :first-child").css('color', 'red');

But CSS will do it as well (CSS :first-child selector), and you should use this route if possible :)

.myClass > :first-child { color: red; }
Sign up to request clarification or add additional context in comments.

1 Comment

thanks nic. i had tried both selectors, but didn't think to use them in combination. my example is a bit simplistic - i need to do some manipulation first, so css wouldn't be the way to go in my situation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.