Style Methods Flashcards

1
Q

In jQuery you can modify the value of a css property, change the color color when a user hovers over the menu class.

A

$(‘.menu’).on(‘mouseenter’, () => {
$(‘.nav’).show();
$(‘.menu’).css(‘color’, ‘#FFFFFF’);
})

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

Using an object how can you make it so that you can modify the color to red, background color to blue and font size to 30 when the menu class is hovered over?

A
$('.menu').on('mouseenter', () => {
$('.nav').show();
$('.menu').css({
color: 'red',
backgroundColor: 'blue',
fontSize: 30
})
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Similar to the css method to change the value of a property, how can you lets say change the font size to 24px when the menu element is hovered over that lasts 200 milliseconds to complete this change?

A
$('.menu').on('mouseenter', () => {
$('.nav').show();
$('.menu').animate({
fontSize: '24px'
}, 200)
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Other than using the css method to modify the value of a css property, what is a better way to modify the color of an element?

A

$(‘.menu’).on(‘mouseenter’, () => {
$(‘.nav’).show();
$(‘.menu’).addClass(‘red’);
})

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

What is a faster method to add and remove a class from a button? Not writing an addClass method on an element than also linking it with an removeClass method.

A

$(‘.menu-button’).on(‘click’, () => {
$(‘.nav-menu’).toggleClass(‘hide’);
$(‘.menu-button’).toggleClass(‘button-active’);
})

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

If you have an textarea element in html and want whatever a user types in to copy above as a preview feature, how can you accomplish this? The preview section is a element with a class of preview. The text area has an id of text.

A

$(‘#text’).on(‘keyup’, function() {
$(‘.preview’).html($(this).val());
})

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

If you want to let the user change the font family when they click an option element from the select element
and apply that family to the preview text, how can you do this?

A
$('#family').change(function() {
var familyValue = $('#family').val();
$('.preview').css('fontFamily', familyValue);
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If you want to change the text of an text area element versus a non text area, what is the difference. Write an example on changing the text of both.
For Text Area:

Write an keyup event handler on the id size, the font size will only change when smaller than 80.

For Non Text Area:

Write an keyup event handler on the preview class which will copy the text written in the text id text area

A

Text Area:

$(document).ready(() => {
$(#size).on('keyup', function() => {
var fontSize = $('#size').val();
if (fontSize < 80) {
$('.preview').css('fontSize', fontSize + 'px');
} else {
alert('Error, font size set to 12');
$('.preview').css('fontSize', 12 + 'px');
$('#size').val(12);
}
})

$(‘#text’).on(‘keyup’, function() => {
$(‘.preview’).html($(this).val());
})
});

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

Using the change method on the changing value of the #font id, and change the font size selected to preview above the text area.

A
$(#font).change(function() {
var fontValue = $('#font').val();

$(‘.preview’).css(‘fontFamily’, fontValue);
})

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