0% found this document useful (0 votes)
2 views

Week 01 HTML-cheat-sheet 01

The document serves as a comprehensive cheat sheet for HTML, CSS, and JavaScript, detailing various tags, properties, and methods used in web development. It includes descriptions of HTML tags for both the <head> and <body> sections, CSS styling properties, and JavaScript methods for DOM manipulation. Additionally, it covers input tags, semantic HTML5 elements, and JavaScript array and string methods, providing essential references for internet application development.

Uploaded by

Hammad Waseem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Week 01 HTML-cheat-sheet 01

The document serves as a comprehensive cheat sheet for HTML, CSS, and JavaScript, detailing various tags, properties, and methods used in web development. It includes descriptions of HTML tags for both the <head> and <body> sections, CSS styling properties, and JavaScript methods for DOM manipulation. Additionally, it covers input tags, semantic HTML5 elements, and JavaScript array and string methods, providing essential references for internet application development.

Uploaded by

Hammad Waseem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

BSCS 633: Internet Application Development

Exam “Cheat Sheet”


HTML
Tags Used in the <head> Section

Tag Description
<title> text </title> title shown on page tab
<meta attribute="value" ... /> page metadata
<link href="url" type="text/css" rel="stylesheet" /> links to a CSS style sheet
<script src="url"></script> link to JavaScript code
comment (can appear in head or
<!-- comments -->
body)

Tags Used in the <body> Section

Tag Display Description


<p> text </p> Block paragraph
<h1> text </h1> Block (h1 for largest to
<h2> text </h2> h6 for smallest)
...
<h6> text </h6>
<hr /> Block horizontal rule (line)
<br /> Block line break
<a href="url"> text </a> Block anchor (link)
Inline-
<img src="url" alt="description" /> image
Block
<em> text </em> Inline emphasis (italic)
<strong> text </strong> Inline strong emphasis (bold)
<ol> Block ordered (ol) and unordered (ul) list;
<li> text </li> list item (li)
<li> text </li>
<li>
<ul>
<li> nested item </li>
<li> nested item </li>
</ul>
</li>
</ol>

1
Tags Used in the <body> Section (Continued)

Tag Display Description


<dl> Block definition list (dl);
<dt> term 1 </dt> term (dt), and its description (dd)
<dd> description 1 </dd>
<dt> term 2 </dt>
<dd> description 2 </dd>
</dl>
<blockquote> Block block-level quotation
<p> text </p> ...
</blockquote>
<q> text </q> Inline inline-level quotation
<code> text </code> Inline computer code (monospace)
<pre> text </pre> Inline pre-formatted text (preserves whitespace)
<table> Block table of data (table)
<caption> text </caption> description of table (caption)
<tr> table row (tr)
<th> heading 1 </th> table heading cell (hr)
<th> heading 2 </th> normal table cell (td)
</tr>
<tr>
<td> cell 1 </td>
<td> cell 2 </td>
</tr>
...
</table>
<div> ... </div> Block block-level section of a page
<span> ... </span> Inline inline-level section of a page

HTML5 Semantic Grouping Tags

Tag Display Description


<header> Block Container for a header of a document
<footer> Block Container for a footer of a document
<article> Block A standalone piece of content (e.g., entire blog post including title, author, etc.)
<section> Block A piece of content that is part of another (e.g., a chapter section of a reading)
Defines some content aside from the content it is placed in (e.g., a sidebar in an
<aside> Block
article)
Specifies the main content of a document. The content inside should be unique to
<main> Block the document and not contain content that is repeated across pages (e.g., sidebars,
nav links, search bars, etc.)

2
HTML Input Tags
Note that input tags are inline tags.

Tag Description
<button type="type"> clickable button
content type can be submit, reset, button
</button>
<input type="type" name="name"> form input tag
content type can be text, number, submit, reset,
</input> checkbox, radio, file, etc.
<textarea rows="num" cols="num"> multi-line text input box
initial text
</textarea>
<label> text </label> clickable text label around a form control
<select> drop-down selection box (select);
<option> text </option> each option within the box (option);
<option> a labeled group of options (optgroup);
<optgroup label="text">
<option> text </option>
<option> text </option>
</optgroup>
...
</select>
<fieldset> a grouped set of form fields with a legend
<legend> text </legend> content
</fieldset>

HTML Entities Reference


Result Description Entity Name
non-breaking space &nbsp;
< less than &lt;
> greater than &gt;
& ampersand &amp;
© copyright &copy;

3
CSS
For the following property and value tables, anything emphasized represents values that should be replaced with
specific units (e.g., length should be replaced with a px, pt, or em for many properties, and color should be
replaced with a valid color value such as a hex or rgb code).

A use of | refers to separation of possible values (where you cannot provide two of these possible values for one
property) and [value value value] refers to a grouping of possible values that can optionally be used together
(e.g., [h-shadow v-shadow blur spread color] for box-shadow).

Selector Types

Name Description Example


Universal Any element * { font: 10pt Arial; }
Element Any element of a given type h1 { text-decoration: underline; }
Grouping Multiple elements of different types h1, h2, h3 { color: purple; }
Class Elements with the given class name .example { text-decoration: underline; }
Id Single element with the given id #example { text-decoration: overline; }
Descendant Elements that are children at any #example h1 { text-decoration: underline; }
level of another specified element
Child Elements that are direct children of #example > p { font-weight: bold; }
another specified element
Attribute Elements that have the specified at- input[selected] - inputs that have the selected attribute
tribute
input[name=’test’] - inputs that have a name ’test’

Background Styles

Property Values
background-attachment scroll | fixed
background-color color | transparent
background-image url | none
background-origin border-box | padding-box | content-box
background-position top left | top center | top right |
center left | center center | center right |
bottom left | bottom center | bottom right
[x-% y-% ] | [x-pos y-pos ]
background-size length | % | auto | cover | contain
background-repeat repeat | repeat-x | repeat-y | no-repeat
background-attachment scroll | fixed

4
Border Styles
Note: Replace ’*’ with any side of the border (top, right, left, bottom) for the desired effect.

Example style: ’border: 2px solid red’ applies a solid red border with a width of 2px to all four sides of
the element, while ’border-left: 2px solid red’ only applies that border to the left border’.

Property Values
border, border-* (shorthand) border-width, border-*-width
border-style, border-*-style
border-color, border-*-color
border-width, border-*-width thin | medium | thick | length
border-style, border-*-style none | hidden | dotted | dashed | solid |
double | groove | rigid | inset | outset
border-color, border-*-color color
box-shadow none | inset | [h-shadow v-shadow blur spread color ]
border-radius length

Font and Text Styles

Property Values
font-style normal | italic | oblique | inherit
font-family fontname
font-size length | %
font-weight normal | bold | inherit
text-align left | right | center | justify
text-decoration none | [underline overline line-through blink]
text-shadow none | [color length ]
letter-spacing, word-spacing normal | length | %
text-indent length | %
text-transform none | capitalize | uppercase | lowercase
list-style-type none | asterisks | box | check | diamond | disc | hyphen |
square | decimal | lower-roman | upper-roman |
lower-alpha | upper-alpha | lower-greek | upper-greek |
lower-latin | upper-latin | footnotes
list-style-image none | url

Color Values

Value Description
colorname standard name of color, such as red, blue, purple, etc.
rgb(redvalue, greenvalue,
Example: red = rgb(255, 0, 0) or red = rgb(100%, 0, 0)
bluevalue)
#RRGGBB Example: red = #FF0000

5
Box Model

Property Values
float left | right | none
height, width auto | length | %
min-height, max-height none | length | %
min-width, max-width
margin, margin-* auto | length | %
padding, padding-* length | %
display none | inline | block | inline-block | flex |
list-item | compact | table | inline-table
overflow, overflow-x, overflow-y visible | hidden | scroll |
auto | no-display | no-content
clear left | right | both | none

Flex Box
(on next page)

6
Property Values Element Type Description
display flex Flex Container Sets all children to become ’flex-items’
justify-content Flex container Indicates how to position the flex-items
in the parent container

flex-start

flex-end

center

space-around

space-between
flex-direction row | row-reverse | Flex container Indicates if the container flows horizon-
column | column-reverse tally (row) or vertically (column)
align-items stretch (default) Flex container Indicates how to space the items inside
the container along the cross axis

flex-start

flex-end

center

baseline
flex-basis auto (default) | length | Both Specifies the default size of an element
% before the extra space is distributed
among the flex-items
order number Flex item Specifies the order in which the ele-
ment appears in the flex container (by
default, flex items are laid out in the
source order)
align-self flex-end | flex-start | Flex item Indicates where to place this specific
center | baseline | item along the cross axis
stretch (default)
7
JavaScript
Window Methods and Properties

Method/Property Description
document Returns a reference to the document contained in the window
Returns an object that reports the values of all CSS properties of an
getComputedStyle(element) element after applying active stylesheets and resolving any basic compu-
tation those values may contain

Document Methods and Properties

Method/Property Description
getElementById(id) Returns a DOM object whose id property matches the specified string
Returns an array-like object of all elements which have all of the given
getElementByClassName(cn)
class names
getElementByName(name) Returns an collection of all elements which have all of the given name
Returns the first DOM element that matches the specified selector, or
querySelector(sel)
group of selectors. If no matches are found, null is returned
Returns a list of the document’s elements that match the specified group
querySelectorAll(sel)
of selectors.
getElementsByTagName(name) Returns a NodeList containing all elements with the specified tag name
createElement(elType) Creates and returns an Element node
createTextNode Creates and returns a Text node

DOM Element Methods and Properties

Method/Property Description
children Returns a collection of an element’s child elements
parentNode Returns the parent node of an element
classList Returns the class name(s) of an element
className Sets or returns the value of the class attribute of an element
appendChild(child) Adds a new child node, to an element as the last child node
addEventListener(event, fn) Attaches an event handler to the specified element
getAttribute(attr) Returns the specified attribute value attr of an element node
innerHTML Sets or returns the content of an element
innerText Sets or returns the text content of the specified node
id Sets or returns the value of the id attribute of an element
removeChild(child) Removes a child node from an element

8
Other DOM Element Properties
Recall that if you have an HTML element on your page that has attributes, you can set those properties through
JavaScript as well. For instance if your

<img id="dogtag" src="img/doggie.jpg" alt="My Cute Dog" />

Your could do the following in your JavaScript code (using the $ alias for document.getElementById):

$("dogtag").alt = "My really cute dog";

Example DOM Element attributes include (other than src, and alt above) are:

Property Description
disabled Whether or not this DOM element is disabled on the page
value The value of the value attribute of a text field
name The value of the name attribute of a a form element
href The href for a link or a tag

DOM Element.classList Methods and Properties

Method/Property Description
Adds specified class values. These values are ignored if they already exist
add(class)
in the list
remove(class) Removes the specified class value
Toggles the listed class value. If the class exists, then removes it and
toggle(class)
returns false, if it did not exist in the list add it and return true
Returns true if the specified class value is exists in the classList for this
contains(class)
element

Event Object Methods and Properties

Method/Property Description
target Returns the element that triggered the event
type Returns the name of the event
Returns the horizontal coordinate of the mouse pointer, relative to the
offsetX
DOM element clicked
Returns the vertical coordinate of the mouse pointer, relative to the DOM
offsetY
element clicked
stopPropagation Prevents further propagation of an event during event flow

9
Event Types

click mousemove keydown change


dblclick mouseout error focus
mouseenter mouseover success submit
mouseleave mouseup load select
mousedown keyup unload resize

JavaScript JSON Methods

Function Description
parse(string) Returns the given string of JSON data as the equivalent JavaScript object
stringify(object) Returns the given object as a string of JSON data

Other handy JavaScript Methods

Function Description
function parses a string argument and returns an integer of the specified
parseInt(string, radix)
radix (the base in mathematical numeral systems)
console.log(string) Writes the string to the JavaScript console

JavaScript Array Methods and Properties

Method/Property Description
length Sets or returns the number of elements in an array
push(el) Adds new elements to the end of an array and returns the new length
pop() Removes and returns the last element of an array
unshift(el) Adds new elements to the beginning of an array and returns the new length
shift() Removes and returns the first element in an array
sort() Sorts the elements of an array
slice(start, end) Selects a part of an array and returns the new array
join() Joins all elements of an array into a string
concat(list2, ...) Joins two or more arrays and returns a copy of the joined arrays
toString() Converts an array to a string and returns the result
indexOf(el) Returns the index of the element in the array, or -1 if not found

10
JavaScript String Methods and Properties

Method/Property Description
length Returns the length of a string
charAt(index) Returns the character at the specified index
Returns the position of the first found occurrence of a specified value in
indexOf(string)
a string
split(delimiter) Splits a string into an array of substrings
substring(start, end) Extracts the characters from a string between two specified indices
trim() Removes whitespace from both ends of a string
toLowerCase() Returns a lowercase version of a string
toUpperCase() Returns an uppercase version of a string
concat(str2, ...) Joins two or more strings and returns a new joined string

JavaScript Timer Functions

Method Description
Executes a function after waiting a specified number of milliseconds.
setTimeout(fn, ms)
Returns a value representing the ID of the timeout being set.
Repeats a given function at every given time-interval. Returns a value
setInterval(fn, ms)
representing the ID of the interval being set.
clearTimeout(id) Stops the execution of the function specified by id
clearInterval(id) Stops the execution of the functions specified by id

JavaScript Math Functions

Method Description
Math.random() Returns a double between 0 (inclusive) and 1 (exclusive)
Math.abs(n) Returns the absolute value of n
Math.min(a, b, ...) Returns the smallest of 0 or more numbers
Math.max(a, b, ...) Returns the largest of 0 or more numbers
Math.round(n) Returns the value of n rounded to the nearest integer
Math.ceil(n) Returns the smallest integer greater than or equal to n
Math.floor(n) Returns the largest integer less than or equal to n
Math.pow(n, e) Returns the base n to the exponent e power, that is, ne
Math.sqrt(n) Returns the square root of n (NaN if n is negative)

11
The Module Pattern
Whenever writing JavaScript, you should use the module pattern, wrapping the content of the code (window.onload
handler and other functions) in an anonymous function. Below is a template for reference:

(function() {
// any module-globals (limit the use of these when possible)

window.onload = function() {
...
};

// other functions
})();

Helper Alias Functions


You may use any of the following alias functions in your exam without defining them:

function $(id) {
return document.getElementById(id);
}

function qs(selector) {
return document.querySelector(selector);
}

function qsa(selector) {
return document.querySelectorAll(selector);
}

Javascript Ajax Fetch Skeleton


//you can assume checkStatus is already included
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response.text();
} else {
return Promise.reject(new Error(response.status + ": " + response.statusText));
}
}

function callAjax(){
let url = ..... // put url string here
fetch(url) // don't worry about cloud9 credentials
.then(checkStatus)
.then(JSON.parse) //optional line for processing json
.then(function(responseJSON) {
//success: do something with the responseJSON
})
.catch(function(error) {
//error: do something with error
});
}

12

You might also like