\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{dwapi} \pdfinfo{ /Title (jquery-to-javascript-quick-ref-guide.pdf) /Creator (Cheatography) /Author (dwapi) /Subject (JQuery to JavaScript Quick Ref Guide Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{097818} \definecolor{LightBackground}{HTML}{F7FAF7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{JQuery to JavaScript Quick Ref Guide Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{dwapi} via \textcolor{DarkBackground}{\uline{cheatography.com/43665/cs/13113/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}dwapi \\ \uline{cheatography.com/dwapi} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 13th October, 2017.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{7.9442 cm} x{9.3258 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{DOM Selectors}} \tn % Row 0 \SetRowColor{LightBackground} \$('\#id') & \seqsplit{document.getElementById('id')} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \$('tagName') & document.getElementsByTagName('tagName')\{\{nl\}\}document.querySelectorAll("tagName") ~ //returns a NodeList \tn % Row Count 10 (+ 7) % Row 2 \SetRowColor{LightBackground} \$('.className') & \seqsplit{document.getElementsByClassName('className')} \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{\$('tagName.className')} & \seqsplit{document.querySelectorAll('tagName.className');} \tn % Row Count 17 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{\$('\#id').text('text')} & \seqsplit{document.getElementById(id).innerHTML} = ''text \tn % Row Count 20 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{\$('\#id').attr('attr'}, 'new value') & \seqsplit{document.getElementById(id).attribute} = new value \tn % Row Count 24 (+ 4) % Row 6 \SetRowColor{LightBackground} .attr \textasciicircum{} or removeAttr() & \seqsplit{document.getElementById("id").setAttribute("attr"}, "val"); ~ // ~ or getAttribute \tn % Row Count 30 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.9442 cm} x{9.3258 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{DOM Selectors (cont)}} \tn % Row 7 \SetRowColor{LightBackground} \$('\#id').css(\{color:red\}) & \seqsplit{Object.assign(document.getElementById('id).style},\{fontSize:"20px",color: red\}); \tn % Row Count 4 (+ 4) % Row 8 \SetRowColor{white} \$( "{[}attribute='value'{]}" ) & document.querySelectorAll('{[}attribute="value"{]}'); \&npsp;~{\bf{IE9+}} \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{In POJS A NodeList object is a list (collection) of nodes extracted from a document} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Events}} \tn % Row 0 \SetRowColor{LightBackground} \$(\#id).click(function()\{\}) & \seqsplit{document.getElementById("id").onclick} =function()\{\} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \$(\#id).on('event', function()\{\}) & \seqsplit{element.addEventListener('click'}, function() \{ ... \}, false); \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{\$(\#id).on('mouseover} click', function () \{ \}) & {[}'click', 'mouseover'{]}.map(function(e) \{ \seqsplit{window.addEventListener(e}, mouseMoveHandler); \}); \tn % Row Count 13 (+ 5) % Row 3 \SetRowColor{white} \$.ready(function ()\{ \}); & \seqsplit{document.addEventListener("DOMContentLoaded"}, function(event) \{ \}) ~ ~{\bf{IE9+}} \tn % Row Count 18 (+ 5) % Row 4 \SetRowColor{LightBackground} \$( window ).load(function()\{ \}); & window.onload = doSomething or function()\{ \}; \tn % Row Count 21 (+ 3) % Row 5 \SetRowColor{white} \$( '\#image' ).load(function()\{ \}); & \seqsplit{imageObj.addEventListener('load'}, function() \{ \}, false); \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{ready and DOMContentLoaded are executed as soon as the HTML has downloaded and the DOM is ready, but it won't wait for other assets. \newline \$(window).load and window.onload are triggered after all external resources (like images) have finished loading} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Enumerables}} \tn % Row 0 \SetRowColor{LightBackground} \$.merge( {[} 0, 1{]}, {[} 2, 3 {]} ) & Joins two or more arrays, and returns a copy of the joined arrays & {[}0, 1 {]}.concat({[}2, 3{]}) \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \$.each({[} 52, 97 {]}, \seqsplit{function(index}, item)\{\}) & Calls a function for each array element & \seqsplit{array.forEach(function(currentValue}, index, arr), function()\{\}) \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \$.grep( {[} 0, 1 {]}, function( item, index )\{\}) & Returns a new array with matching elements & {[}1,2{]}.filter(function(currentValue, index, arr)\{\}) \tn % Row Count 16 (+ 6) % Row 3 \SetRowColor{white} \$.map( array, function( item, index ) \{ return doSomething \}); & Creates a new array with the result of calling a function on each array element & \seqsplit{array.map(function(currentValue}, index, arr)\{ return doSomething;\} ) \tn % Row Count 23 (+ 7) % Row 4 \SetRowColor{LightBackground} \seqsplit{\$.unique(array)} & Remove duplicates from an array & arr.filter( function( item, index, inputArray ) \{ \{\{nl\}\}~ ~ return \seqsplit{inputArray.indexOf(item)} == index; \{\{nl\}\} \}); \tn % Row Count 33 (+ 10) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Enumerables (cont)}} \tn % Row 5 \SetRowColor{LightBackground} N/A & Reduce the values of an array to a single value (going \seqsplit{left-to-right)} & {[}1, 2, 3{]}.reduce(function(total, num)\{ return total + num; \}) \tn % Row Count 6 (+ 6) % Row 6 \SetRowColor{white} N/A & Reduce the values of an array to a single value (going \seqsplit{right-to-left)} & {[}1, 2, 3{]}.reduceRight(function(total, num)\{ return total + num; \}) \tn % Row Count 12 (+ 6) % Row 7 \SetRowColor{LightBackground} N/A & Removes the first element of an array, and returns that element & {[}1, 2, 3{]}.shift() \tn % Row Count 17 (+ 5) % Row 8 \SetRowColor{white} N/A & Adds new elements to the beginning of an array, and returns the new length & {[}1, 2, 3{]}.unshift(4, 5) \tn % Row Count 23 (+ 6) % Row 9 \SetRowColor{LightBackground} N/A & Add items to the array based on index (rather than shift or push) & {[}1, 2, 3, 4{]}.splice(2, 0, "a", "b") ~ // {[} 1, 2, "a", "b", 3, 4 {]} \tn % Row Count 29 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{DOM Manipulation}} \tn % Row 0 \SetRowColor{LightBackground} var newElement = \$("\textless{}div\textgreater{}", \{"class": "something"\}); & var newElement = \seqsplit{document.createElement('div'},\{ class: 'something'\}); \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \seqsplit{\$(newElement).text('text')} & var node = \seqsplit{document.createTextNode("This} is a new paragraph."); \{\{nl\}\}newElement.appendChild(node); \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{\$(\#parentNode).append(\$(newElement))} & var parentNode = \seqsplit{document.getElementById("div1");} \{\{nl\}\}element.appendChild(para); \tn % Row Count 14 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{\$(\#parentNode).prepend(\$(newElement))} & \seqsplit{parentNode.insertBefore(newElement}, \seqsplit{parentNode.firstChild);} \tn % Row Count 17 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{\$(newElement).before(} \$( "\#firstChild" ) ); & \seqsplit{parentNode.insertBefore(newElement}, \seqsplit{parentNode.firstChild);} \tn % Row Count 20 (+ 3) % Row 5 \SetRowColor{white} \$( "\#inner" ).wrap( \$(outer) ); & \seqsplit{document.getElementById("outer").innerHTML} = raw\_html or newElement; \tn % Row Count 24 (+ 4) % Row 6 \SetRowColor{LightBackground} \seqsplit{\$(\#parentNode).remove()} & \seqsplit{parentNode.removeChild(child);} \tn % Row Count 26 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{\$(\#oldNode).replaceWith(\$(\#newNode))} & \seqsplit{parentNode.replaceChild(newNode}, oldNode); \tn % Row Count 29 (+ 3) % Row 8 \SetRowColor{LightBackground} \$("\#id").clone() & \seqsplit{ocument.getElementById("id").cloneNode(true);} \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{DOM Manipulation (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \seqsplit{\$("\#wrap").is(":empty")} & \seqsplit{document.getElementById("id").hasChildNodes()} \tn % Row Count 3 (+ 3) % Row 10 \SetRowColor{white} \seqsplit{\$(\#id).addClass('newClass')} or removeClass() & \seqsplit{document.getElementById("myelement").classList.add("newClass");} or .remove() ~ ~ {\bf{IE10+}} \tn % Row Count 8 (+ 5) % Row 11 \SetRowColor{LightBackground} \seqsplit{\$(\#id).hasClass('myclass')} & \seqsplit{document.getElementById("myelement").classList.contains("myclass");} ~ ~ {\bf{IE110+}} \tn % Row Count 13 (+ 5) % Row 12 \SetRowColor{white} \seqsplit{\$(\#id).toggleClass('myclass')} & \seqsplit{document.getElementById("myelement").classList.toggle("myclass");} ~ ~ {\bf{IE110+}} \tn % Row Count 18 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{toggleClass and toggle will remove a class if present, or add it if not} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}