3

What does the > sign mean in (#todoList > div) in the following javascript?

$('#btnClear').click(function () {
    $('#todoList > div').each(function () {
        var entity = $(this).data('entity');
        $todo.context.TodoEntries.remove(entity);
    });
    $todo.context.saveChanges(updateView);
});

In the Html File the #todoList is the id of a div.

<div id="todoList"></div>

And in this statement

 $('#wrapper>div:not(#providerSelection)')

What is ":not"?

Sourav301
  • 1,259
  • 1
  • 14
  • 24

5 Answers5

8

It's a child selector. This is not a javascript feature but css. jQuery implement it on its selector engine but it has nothing to do with javascript.

A child selector matches when an element is the child of some element. A child selector is made up of two or more selectors separated by ">".

The following rule sets the style of all P elements that are children of BODY:

body > P { line-height: 1.3 }

The following example combines descendant selectors and child selectors:

div ol>li p

It matches a P element that is a descendant of an LI; the LI element must be the child of an OL element; the OL element must be a descendant of a DIV. Notice that the optional white space around the ">" combinator has been left out.

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
  • It's a Selectors API feature, and the JavaScript DOM implements its `querySelector[All]` methods with most of that API. jQuery/Sizzle uses `.querySelectorAll()` as the default for its DOM selection. –  Jul 01 '13 at 16:46
7

It's not JavaScript syntax but CSS selector syntax, here passed in a JQuery selector.

It's the "direct child" selector.

It means it selects all div elements that are child nodes one level down from the element with id todoList.

This would apply to elements with id A and B here :

<div id="todoList">
  <div id=A>
     <div id=C>
  </div>
  <span id=D></span>
  <div id=B></div>
</div>
Derek Peterson
  • 593
  • 2
  • 8
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

$("#todoList > div") means select div elements that are direct descendants (children) of the element with id="todoList".

Samuel Reid
  • 1,756
  • 12
  • 22
0

its a css selector, no meaning in javascript itself except "greater than", in css it means the previous selectors direct child.

Patrick Evans
  • 41,991
  • 6
  • 74
  • 87
0

Its a child selector of parent

Selects all direct child elements specified by “child” of elements specified by “parent”.

Means child div inside #todoList

SEE API --> http://api.jquery.com/child-selector/

The child combinator (E > F) can be thought of as a more specific form of the descendant combinator (E F) in that it selects only first-level descendants.

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68