Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help understanding jQuery selector example

The following code was taking from the timers jQuery plugin demo. I don't understand what is happening in the selector in line 2. It seems it is selecting the p element, but then what is the second argument after the comma - demos - there for?

jQuery:

var demos = $("div.wrapper div.demos");             
$(".uncontrolled-interval p", demos).everyTime(1000,function(i) {
                    $(this).html(i);
                });

HTML:

<div class="wrapper"> 
    <div class="demos">         
        <div class="uncontrolled-interval"> 
            <p>I am transient... *sigh*</p> 
        </div>      
    </div> 
</div>

Thanks

like image 983
Yarin Avatar asked May 12 '11 19:05

Yarin


1 Answers

It specifies the context of the search. Basically a filter.

http://api.jquery.com/jQuery#expressioncontext

So in this example it searches the demos element for .uncontrolled-interval p. If you have this markup, it would still only select the one in demos.

<div class="wrapper">          
    <div class="uncontrolled-interval"> 
        <p>I am transient... *sigh*</p> //Will not select
    </div>     
    <div class="demos">         
        <div class="uncontrolled-interval"> 
            <p>I am transient... *sigh*</p> //Will select
        </div>      
    </div> 
</div>
like image 144
Dustin Laine Avatar answered Sep 22 '22 10:09

Dustin Laine