tags:

views:

27

answers:

1

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?

+4  A: 

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; }
Nick Craver
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.
murraybiscuit