When to use jQuery wrapper methods instead of javascript built-in methods

What jQuery methods should be avoided in favor of inline methods / properties?

Example:

$('#el').each(function(){

  // this.id vs $(this).attr('id');
  // this.checked vs $(this).is(':checked');

});;
+5
source share
3 answers

I use the direct javascript property, for example this.idin the following cases:

  • Whenever he does exactly what I want.
  • When speed is important.
  • When all browsers care about supporting exactly what I need.

I use jQuery access method when:

  • There are issues with cross-browser support, or I'm not sure there are no cross-browser issues.
  • When the jQuery method has more or more functionality, which is useful in my circumstances.
  • When the jcuery chain and chain part works better,
  • jQuery , / jQuery.

: str = $(elem).html() str = elem.innerHTML, $(elem).html(str) elem.innerHTML = str;, jQuery , , innerHTML.

+3

, , . / js, :

  • , . .
  • ,
  • , . :
    • ( )
    • (, , )
    • - .

:) . , , , .

- , !

+1

DOM . , (id checked), DOM 100% jQuery , .

, : readonly, disabled, selected . . className 100% . . , jQuery, , ( ).

A regular stack overflow Andy Earnshaw wrote about this on his blog: http://whattheheadsaid.com/2010/10/utilizing-the-awesome-power-of-jquery-to-access-properties-of-an-element

+1
source

All Articles