JQuery selection options

First post here, please be careful :)

I searched all over the network and I'm not sure that I am looking for suitable terms for either his name. But what do the secondary options do in the jQuery selector? For instance:

$('.results table', this.parent().prev())

The second batch of options in the results table corresponds to them not sure what it actually does? This is similar to $('.results table').parent().prev(), for example. Sorry, I just shot this code as an example.

Rate pointers as I am just learning jQuery.

+3
source share
3 answers

- , . , , <tr> <table> <tr> <td>.

$('table tr').each(function() {
    $('td:eq(1)', this).doSomething(); // the function context, this, is the `<tr>`
                                       // element in each iteration
});

. , API jQuery :)

+6

, - "" , . :

$('secondParameterSelector').find('firstParameterSelector') ...

this.parent().prev().find('.results table')

(, this.parent().prev() jQuery, )

+2

- . , span div:

$("div").click(function(){
  alert( $("span:first", this).text() );
});

thisin this example refers to the one that has ever been pressed div. This is our context. This "context" can be a dom-element, document, or jQuery object.

Further reading: http://api.jquery.com/jQuery/

0
source

Source: https://habr.com/ru/post/1733986/


All Articles