views:

27

answers:

1

I want to write a select something like...

#window_4 > content > p:eq(0)

I think I have this correct, but I have a few selectors that are all similar but I can't test them all at once.

Am I right in saying this is selecting an element, who is the fist p tag child of a content tag that is a child of a tag with id 'window_4'

If I have gotten this wrong, can you give me some pointers. Would love to be able to simplify this code, I have more code selecting the tag I am after then actually doing stuff with them.

+3  A: 

Looks good to me, although you can make it a bit more readable by substituting p:eq(0) for p:first.

Edit for comment:

jQuery always returns an array of elements, no matter whether 0, 1 or many elements were found. On these elements, yes, you can perform JS functions, such as innerHTML. You can access each element returned by jQuery just as if you would any other array:

$(".red")[0].innerHTML = "Glen Crawford";

More info: http://groups.google.com/group/jquery-ui/browse_thread/thread/34551a757f139ae1/20111f82c2596426

GlenCrawford
some times I will wanting other p tags from with in the content tag. Can you also tell me, does jquery return an actual element here, one that I can then go onto perform other JS functions, such as innerHTML for example?
thecoshman
Thanks, this does work. its a lot more compact this way.
thecoshman