Defines a specific set of reusable tasks
Input parameters
Do stuff, return data
function
: keyword, like var
Function Name
Body for execution, like an if
statement
We often want to directly use the data the function creates. The return
method does just that.
{ name: "Brendan" }
Key = name Value = Brendan
Find elements (traverse the DOM):
$("<css selector>");
Manipulate those elements:
$(target).css()
, $(target).html()
$("<css selector>");
Returns results in array
$("h1");
Finds all h1 header elements
$(".header .nav");
Finds class .nav in .header
$(target).html("<html string>")
Inserts (overwrites) HTML in selected elements
$(target).html()
Returns all HTML of selected element as a string
$(target).css("property-name","value")
Changes inline CSS values for selected elements
$(target).css("property-name")
Returns value of CSS property as a string
$(target).hide()
Hides all matched elements by setting their inline style to display: none;
$(target).show()
Reveals matched elements by switching their display property to block/inline;
$(target).remove()
Removes the matched element(s) from the DOM entirely
$(target).addClass("className")
Adds class to all matched elements Note: in this case, you should not use a period preceding your class name
$(target).removeClass("className")
Removes class from all matched elements
$(target).toggleClass("className")
Adds class if not currently applied, otherwise removes it
$(target).append("content")
Inserts content at the end of each matched element
$(target).prepend("content")
Inserts content at the beginning of each matched element
User has pressed and released the mouse button
Mouse button is pressed over the element
Mouse button is released over the element
User has moved the mouse over the element
Mouse has entered the target element
Mouse has left the target element