2

I have the following line in my js

var description = jqref.children('.category_info').children('.description').children('p').html();

which works exactly how I want it, though to me it feels way too clunky which feels like I am overlooking a better selector method.

I'm fairly certain I ought to be using the > direct child symbol but can't seem to implement it in the normal way as I am already dealing with a jquery object.

Zak Henry
  • 2,075
  • 2
  • 25
  • 36

1 Answers1

5

Use find with the child selector. I learned something new; you can prepend the selector with a child selector to make sure that you only get children:

var description = jqref.find('> .category_info > .description > p').html();

JSFiddle: http://jsfiddle.net/5SktL/

Dennis
  • 32,200
  • 11
  • 64
  • 79
  • The problem with that is that there (may be) many descendants of jqref that match that selector. I only want the exact `jqref > .category_info > .description > p` item. This selector would also match `jqref > .children > otherref > .category_info > .description > p` – Zak Henry Sep 15 '11 at 01:11
  • 1
    " I learned something new; you can prepend the selector with a child selector to make sure that you only get children" -- new to me too! – maxedison Sep 15 '11 at 01:57
  • Nice! I did not know that you could start with a `>` – Zak Henry Sep 15 '11 at 01:58