-2

I use this JQuery-Selector:

$("#foo > .row")

PHPStrom shows me Inefficient jquery selector.

Whats the more efficient way to select only direct childs of one ID?

mdunisch
  • 3,627
  • 5
  • 25
  • 41
  • While the linked answer isn't an exact duplicate, it does also cover this scenario specifically. – Kevin B May 16 '14 at 17:58

1 Answers1

2

Select the element by id, then get it's children.

$("#foo").children()

This is more efficient because it first uses document.getElementById, then it gets the element's childNodes that are elements, skipping the selector engine completely.

Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • +1 Verified this in Chrome 34 and IE 11 [jsperf.com](http://jsperf.com/jquery-direct-child-selector-example)... – War10ck May 16 '14 at 18:00
  • 2
    leaving this here since the answers in the linked question don't specifically use this example – Kevin B May 16 '14 at 18:00