Skip to content

Instantly share code, notes, and snippets.

@airportyh
Created March 12, 2013 00:36
Show Gist options
  • Select an option

  • Save airportyh/5139289 to your computer and use it in GitHub Desktop.

Select an option

Save airportyh/5139289 to your computer and use it in GitHub Desktop.
Some things to avoid and defer to jQuery when writing Javascript:
document.getXYZ -> $('...')
document.getElementById('abc') is okay, but some others are not. Might as well use $('#abc').
querySelector -> $('...')
querySelector is not supported in IE7 - IE8, use jQuery.
string.trim -> $.trim
' abc '.trim() is not supported in IE7 - IE8. Use jQuery: $.trim(' abc ')
innerHTML -> text()
Most of the time you are doing elm.innerHTML you really mean to do elm.innerText, but you also know that innerText doesn't work on all browsers. So just use jQuery: $('...').text()
in general terms:
don't use any dom api directly, if you are not sure, double check with mdn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment