Some questions about 25 jquery tips

I just read this: http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx

And you had some questions about some of the suggested tricks:

9 - Give your selectors context:

What is the difference between using context and using a more specific selector?

Instead of doing

var selectedItem = $('#listItem' + i, $('.myList'));   

What about

var selectedItem = $('.myList>#listItem' + i); 

Which one is faster / better, or is there no difference?

12 - Learn about event delegation:

I would suggest that with a low number of handlers, the delegation event is slower than normal binding.

How many handlers is the time when you should start using event delegation?

, ( , "" ) dom, , , . ?

: , ? - 10 2 .

13 -

14 - , jQuery () :

? ? , , , , DOM.

!

+5
4

9 - :

var selectedItem = $('#listItem' + i, $('.myList'));

V/S

var selectedItem = $('#listItem' + i);

. , ...

. ID. . , .

, .

:

var selectedItem = $('.myList>#listItem' + i);

, . , , , .

, :

var ctx = selectedItem = $('.myList')
for (var i=0; i<1000; i++) {
    var selectedItem = $('.listItem' + i, ctx);
}

.

, , , , - .

- , ?

, . 99% .

+4

, , , , .

9 - :

, iframe . , .

:

JQuery (, )
jQuery . jQuery . - ( CSS), .

, , $() DOM HTML-. , DOM jQuery, .

14 - , jQuery () :

expando. . . , . .

PS.

+2

(9)

id, ... , ( )

(, , (), , ), , ...

//LI elems with CSS class "foo"
//but only inside the element with the ID "onlyInHere"
$('li.foo', '#onlyInHere')
+1

# 9:

, , , , , , : $('div > span')..

, .

getElementsByTagName, .

", " - DOM , (, ) .

# 12:

, , (, ) , . , . .

# 13:

, , , , , . HTML. : "", , , , . "selected" jQuery (: , HTTP- ).

# 14:

Classes are limited by the type and amount of data that you can (or should) store in them. Data is a more flexible way to store large amounts of state data for HTML elements.

+1
source

All Articles