Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 1.34 KB

0_Easy_Wins.md

File metadata and controls

22 lines (19 loc) · 1.34 KB

Easy wins.

You're listening to this, and thinking, I'm not going to refactor all my code. That's not what I'm saying. At first, just go native when you need the performance, like in loops.

Here are a few examples of when jQuery actually makes the code more verbose than it would otherwise be because of the almighty $.

  • myNode.id vs $(this).attr('id'). yes, always.
  • myNode.value vs $(this).val()
  • selectNode.selectedIndex on a <select> to get the selected index
  • selectNode.options on a <select> to get a list of options
  • tableNode.rows on a <table> to get a collection of <tr> elements
  • trNode.cells on a <tr> to get a collection of cells
  • myEl.parentNode to get a direct parent
  • myInput.checked vs $(this).is(':checked') to get the state of a checkbox
  • myRadio.selected to get the state of an option
  • myInput.disabled to read the state of an input or button
  • myInput.readOnly to get the readOnly state of an input
  • anchorOrLinkNode.href on an <a>, <link> to get its href
  • myAnchorNode.hostname on an <a> to get the domain of its href
  • myAnchorNode.pathname on an <a> to get the path of its href
  • myAnchorNode.search on an <a> to get the querystring of its href
  • myNode.src on any element where you can set a src