This is Lab 2 of the Beginning jQuery course. In this lab, we will work on the 2 topics:
The addClass
and removeClass
is one of the key technique in jQuery which is often underestimated. By combining CSS styles, we can create visual changes by using these methods.
There are many situations that addClass and removeClass can make the code much simpler and elegant than changing the styles directly.
http://codepen.io/makzan/pen/azRQaP
This example shows how we can toggle visual styles by using the addClass
and removeClass
function.
Given the following style in CSS.
input.error {
border: 1px solid FIREBRICK;
box-shadow: 0 0 4px FIREBRICK;
background: WHITE;
color: BLACK;
}
We can then toggle the error state by the following jQuery code.
$('input').addClass('error');
$('input').removeClass('error’);
The example code is based on the input exercise from Lab 1. In lab 1, I suggested you to add more inputs to the form. For example:
text
and html
method. Try to show more specific error messages when the .error-message
element shows. Make sure you have targeted multiple errors.We can listen to the keydown
event and remove all error effects. This is helpful because we know the user is trying to fix the error.
// Remove any error when form changes.
$('form input').keydown(function(){
$('input').removeClass('error');
$('.error-message').hide();
});
Demo: http://codepen.io/makzan/pen/OPBrym
Can we check the form during the user is still inputting? We don’t need to wait until the form submission to indicate the error messages. Try to make the error messages respond instantly when user is inputting the form.
Here are several events that might be helpful:
The following steps show how we can build an image slideshow by using jQuery and CSS transition.
In step 1, we defined the images list in HTML. It shows that we are listing a collection of content by using the HTML list structure.
In step 2, we style the slideshow layout with CSS position property. There is no any slideshow yet.
In step 3, we add the jQuery logic which rotate the images in a time interval.
In step 4, we animate the slideshow with CSS transition and transform.
In extra steps, we explore other animating styles by only changing the CSS.
This slideshow example provides a solid foundation. This is production ready and can be modified to fit different usages in your next web projects.
currentIndex
variable to show next or previous slide.Here is a lucky draw effect that I created using similar technique. I used it to randomly selected one student to answer question in my previous class.
http://codepen.io/makzan/pen/WbeXRq
Please use chat to send me your exercises. I’ll check them and reply you with suggestions. For any questions or queries, please also raise them. I’m here to help.
—Thomas
This is Lab 2 of the Beginning jQuery course. In this lab, we will work on the 2 topics:
The addClass
and removeClass
is one of the key technique in jQuery which is often underestimated. By combining CSS styles, we can create visual changes by using these methods.
There are many situations that addClass and removeClass can make the code much simpler and elegant than changing the styles directly.
http://codepen.io/makzan/pen/azRQaP
This example shows how we can toggle visual styles by using the addClass
and removeClass
function.
Given the following style in CSS.
input.error {
border: 1px solid FIREBRICK;
box-shadow: 0 0 4px FIREBRICK;
background: WHITE;
color: BLACK;
}
We can then toggle the error state by the following jQuery code.
$('input').addClass('error');
$('input').removeClass('error’);
The example code is based on the input exercise from Lab 1. In lab 1, I suggested you to add more inputs to the form. For example:
text
and html
method. Try to show more specific error messages when the .error-message
element shows. Make sure you have targeted multiple errors.We can listen to the keydown
event and remove all error effects. This is helpful because we know the user is trying to fix the error.
// Remove any error when form changes.
$('form input').keydown(function(){
$('input').removeClass('error');
$('.error-message').hide();
});
Demo: http://codepen.io/makzan/pen/OPBrym
Can we check the form during the user is still inputting? We don’t need to wait until the form submission to indicate the error messages. Try to make the error messages respond instantly when user is inputting the form.
Here are several events that might be helpful:
The following steps show how we can build an image slideshow by using jQuery and CSS transition.
In step 1, we defined the images list in HTML. It shows that we are listing a collection of content by using the HTML list structure.
In step 2, we style the slideshow layout with CSS position property. There is no any slideshow yet.
In step 3, we add the jQuery logic which rotate the images in a time interval.
In step 4, we animate the slideshow with CSS transition and transform.
In extra steps, we explore other animating styles by only changing the CSS.
This slideshow example provides a solid foundation. This is production ready and can be modified to fit different usages in your next web projects.
currentIndex
variable to show next or previous slide.Here is a lucky draw effect that I created using similar technique. I used it to randomly selected one student to answer question in my previous class.
http://codepen.io/makzan/pen/WbeXRq
Please use chat to send me your exercises. I’ll check them and reply you with suggestions. For any questions or queries, please also raise them. I’m here to help.
—Thomas
This is Lab 2 of the Beginning jQuery course. In this lab, we will work on the 2 topics:
The addClass
and removeClass
is one of the key technique in jQuery which is often underestimated. By combining CSS styles, we can create visual changes by using these methods.
There are many situations that addClass and removeClass can make the code much simpler and elegant than changing the styles directly.
http://codepen.io/makzan/pen/azRQaP
This example shows how we can toggle visual styles by using the addClass
and removeClass
function.
Given the following style in CSS.
input.error {
border: 1px solid FIREBRICK;
box-shadow: 0 0 4px FIREBRICK;
background: WHITE;
color: BLACK;
}
We can then toggle the error state by the following jQuery code.
$('input').addClass('error');
$('input').removeClass('error’);
The example code is based on the input exercise from Lab 1. In lab 1, I suggested you to add more inputs to the form. For example:
text
and html
method. Try to show more specific error messages when the .error-message
element shows. Make sure you have targeted multiple errors.We can listen to the keydown
event and remove all error effects. This is helpful because we know the user is trying to fix the error.
// Remove any error when form changes.
$('form input').keydown(function(){
$('input').removeClass('error');
$('.error-message').hide();
});
Demo: http://codepen.io/makzan/pen/OPBrym
Can we check the form during the user is still inputting? We don’t need to wait until the form submission to indicate the error messages. Try to make the error messages respond instantly when user is inputting the form.
Here are several events that might be helpful:
The following steps show how we can build an image slideshow by using jQuery and CSS transition.
In step 1, we defined the images list in HTML. It shows that we are listing a collection of content by using the HTML list structure.
In step 2, we style the slideshow layout with CSS position property. There is no any slideshow yet.
In step 3, we add the jQuery logic which rotate the images in a time interval.
In step 4, we animate the slideshow with CSS transition and transform.
In extra steps, we explore other animating styles by only changing the CSS.
This slideshow example provides a solid foundation. This is production ready and can be modified to fit different usages in your next web projects.
currentIndex
variable to show next or previous slide.Here is a lucky draw effect that I created using similar technique. I used it to randomly selected one student to answer question in my previous class.
http://codepen.io/makzan/pen/WbeXRq
Please use chat to send me your exercises. I’ll check them and reply you with suggestions. For any questions or queries, please also raise them. I’m here to help.
—Thomas
This is Lab 2 of the Beginning jQuery course. In this lab, we will work on the 2 topics:
The addClass
and removeClass
is one of the key technique in jQuery which is often underestimated. By combining CSS styles, we can create visual changes by using these methods.
There are many situations that addClass and removeClass can make the code much simpler and elegant than changing the styles directly.
http://codepen.io/makzan/pen/azRQaP
This example shows how we can toggle visual styles by using the addClass
and removeClass
function.
Given the following style in CSS.
input.error {
border: 1px solid FIREBRICK;
box-shadow: 0 0 4px FIREBRICK;
background: WHITE;
color: BLACK;
}
We can then toggle the error state by the following jQuery code.
$('input').addClass('error');
$('input').removeClass('error’);
The example code is based on the input exercise from Lab 1. In lab 1, I suggested you to add more inputs to the form. For example:
text
and html
method. Try to show more specific error messages when the .error-message
element shows. Make sure you have targeted multiple errors.We can listen to the keydown
event and remove all error effects. This is helpful because we know the user is trying to fix the error.
// Remove any error when form changes.
$('form input').keydown(function(){
$('input').removeClass('error');
$('.error-message').hide();
});
Demo: http://codepen.io/makzan/pen/OPBrym
Can we check the form during the user is still inputting? We don’t need to wait until the form submission to indicate the error messages. Try to make the error messages respond instantly when user is inputting the form.
Here are several events that might be helpful:
The following steps show how we can build an image slideshow by using jQuery and CSS transition.
In step 1, we defined the images list in HTML. It shows that we are listing a collection of content by using the HTML list structure.
In step 2, we style the slideshow layout with CSS position property. There is no any slideshow yet.
In step 3, we add the jQuery logic which rotate the images in a time interval.
In step 4, we animate the slideshow with CSS transition and transform.
In extra steps, we explore other animating styles by only changing the CSS.
This slideshow example provides a solid foundation. This is production ready and can be modified to fit different usages in your next web projects.
currentIndex
variable to show next or previous slide.Here is a lucky draw effect that I created using similar technique. I used it to randomly selected one student to answer question in my previous class.
http://codepen.io/makzan/pen/WbeXRq
Please use chat to send me your exercises. I’ll check them and reply you with suggestions. For any questions or queries, please also raise them. I’m here to help.
—Thomas