jQuery Flashcards

1
Q

remove a class

A

Description: Remove a single class, multiple classes, or all classes from each element in the set of matched elements.

removeClass( [className ] )

removeClass( function(index, class) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

add a class

A

.addClass( className )

.addClass( function(index, currentClass) )

function is a function returning one or more space-separated class names to be added to the existing class name(s). Receives the index position of the element in the set and the existing class name(s) as arguments. Within the function, this refers to the current element in the set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

set or return the text content of selected elements

A

.text()

can also return the content of a callback function:

.text(function(x) {return “bob” + x;});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

set or return the content of selected elements, including HTML markup

A

.html()

can also return the content of a callback function:

.html(function(x) {return “<div>” + x + “</div>”;});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

set or return the value of form fields

A

.val()

can also return the content of a callback function:

.val(function(x) {return “bob” + x;});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

html vs text vs val

getters and setters

A

GETTERS

.text returns the combined text contents of all matching elements

.html returns the html content of the first matching element

.val gets the value of the input element, regardless of type

SETTERS
$(“#div1”).html(‘<a>Link</a><b>hello</b>’);

$(“#div2”).text(‘<a>Link</a><b>hello</b>’);

div1 (html) recognizes html elements in a string:
Linkhello //”Link” is underlined, “hello” is in bold

div2 (text) treats everything in a string as text:
<a>Link</a><b>hello</b>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Add or remove one or more classes from each element in the set of matched elements, depending on either the class’s presence or the value of the switch argument.

A

toggleClass(className, switch);

if className is absent or switch === true, then the className is added. Otherwise, className is removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly