Style Methods Flashcards
In jQuery you can modify the value of a css property, change the color color when a user hovers over the menu class.
$(‘.menu’).on(‘mouseenter’, () => {
$(‘.nav’).show();
$(‘.menu’).css(‘color’, ‘#FFFFFF’);
})
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?
$('.menu').on('mouseenter', () => { $('.nav').show(); $('.menu').css({ color: 'red', backgroundColor: 'blue', fontSize: 30 }) })
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?
$('.menu').on('mouseenter', () => { $('.nav').show(); $('.menu').animate({ fontSize: '24px' }, 200) })
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?
$(‘.menu’).on(‘mouseenter’, () => {
$(‘.nav’).show();
$(‘.menu’).addClass(‘red’);
})
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.
$(‘.menu-button’).on(‘click’, () => {
$(‘.nav-menu’).toggleClass(‘hide’);
$(‘.menu-button’).toggleClass(‘button-active’);
})
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.
$(‘#text’).on(‘keyup’, function() {
$(‘.preview’).html($(this).val());
})
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?
$('#family').change(function() { var familyValue = $('#family').val(); $('.preview').css('fontFamily', familyValue); })
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
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());
})
});
Using the change method on the changing value of the #font id, and change the font size selected to preview above the text area.
$(#font).change(function() { var fontValue = $('#font').val();
$(‘.preview’).css(‘fontFamily’, fontValue);
})