Add class on click and then remove class on delay
up vote
0
down vote
favorite
I want a class to be added to a class when a button is pressed then after a few seconds I want the class removed.
So far I have the code for adding the class when the button is pressed:
$( ".overlay-close-button" ).click(function() {
$( ".icon_holder" ).addClass('magictime tinRightIn');
});
What would the code be to remove the class 'magictime tinRightIn' from 'icon_holder' after lets say 2s after the button class 'overlay-close-button' is clicked?
javascript
add a comment |
up vote
0
down vote
favorite
I want a class to be added to a class when a button is pressed then after a few seconds I want the class removed.
So far I have the code for adding the class when the button is pressed:
$( ".overlay-close-button" ).click(function() {
$( ".icon_holder" ).addClass('magictime tinRightIn');
});
What would the code be to remove the class 'magictime tinRightIn' from 'icon_holder' after lets say 2s after the button class 'overlay-close-button' is clicked?
javascript
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want a class to be added to a class when a button is pressed then after a few seconds I want the class removed.
So far I have the code for adding the class when the button is pressed:
$( ".overlay-close-button" ).click(function() {
$( ".icon_holder" ).addClass('magictime tinRightIn');
});
What would the code be to remove the class 'magictime tinRightIn' from 'icon_holder' after lets say 2s after the button class 'overlay-close-button' is clicked?
javascript
I want a class to be added to a class when a button is pressed then after a few seconds I want the class removed.
So far I have the code for adding the class when the button is pressed:
$( ".overlay-close-button" ).click(function() {
$( ".icon_holder" ).addClass('magictime tinRightIn');
});
What would the code be to remove the class 'magictime tinRightIn' from 'icon_holder' after lets say 2s after the button class 'overlay-close-button' is clicked?
javascript
javascript
asked Nov 27 '14 at 3:15
CodeOut
1026
1026
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
A slight modification to @ymz answer. You would probably like to cancel the previously set "setTimeout callback" if the user clicks within 2 seconds.
var timeoutHandler = null;
$( ".overlay-close-button" ).click(function()
{
$( ".icon_holder" ).addClass('magictime tinRightIn');
if (timeoutHandler) clearTimeout(timeoutHandler);
timeoutHandler = setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
1
down vote
setTimeout or setInterval in javascript might do the trick. for instance:
$( ".overlay-close-button" ).click(function()
{
// problem: $( ".icon_holder" ) selects multiple elements!!!
$( ".icon_holder" ).addClass('magictime tinRightIn');
setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
0
down vote
You would use setTimeout()
to achieve that.
setTimeout(function() {
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2e3);
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
A slight modification to @ymz answer. You would probably like to cancel the previously set "setTimeout callback" if the user clicks within 2 seconds.
var timeoutHandler = null;
$( ".overlay-close-button" ).click(function()
{
$( ".icon_holder" ).addClass('magictime tinRightIn');
if (timeoutHandler) clearTimeout(timeoutHandler);
timeoutHandler = setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
1
down vote
accepted
A slight modification to @ymz answer. You would probably like to cancel the previously set "setTimeout callback" if the user clicks within 2 seconds.
var timeoutHandler = null;
$( ".overlay-close-button" ).click(function()
{
$( ".icon_holder" ).addClass('magictime tinRightIn');
if (timeoutHandler) clearTimeout(timeoutHandler);
timeoutHandler = setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
A slight modification to @ymz answer. You would probably like to cancel the previously set "setTimeout callback" if the user clicks within 2 seconds.
var timeoutHandler = null;
$( ".overlay-close-button" ).click(function()
{
$( ".icon_holder" ).addClass('magictime tinRightIn');
if (timeoutHandler) clearTimeout(timeoutHandler);
timeoutHandler = setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
A slight modification to @ymz answer. You would probably like to cancel the previously set "setTimeout callback" if the user clicks within 2 seconds.
var timeoutHandler = null;
$( ".overlay-close-button" ).click(function()
{
$( ".icon_holder" ).addClass('magictime tinRightIn');
if (timeoutHandler) clearTimeout(timeoutHandler);
timeoutHandler = setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
answered Nov 27 '14 at 4:04
Diptendu
1,7781824
1,7781824
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
add a comment |
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
Worked perfectly thanks
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
1
down vote
setTimeout or setInterval in javascript might do the trick. for instance:
$( ".overlay-close-button" ).click(function()
{
// problem: $( ".icon_holder" ) selects multiple elements!!!
$( ".icon_holder" ).addClass('magictime tinRightIn');
setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
1
down vote
setTimeout or setInterval in javascript might do the trick. for instance:
$( ".overlay-close-button" ).click(function()
{
// problem: $( ".icon_holder" ) selects multiple elements!!!
$( ".icon_holder" ).addClass('magictime tinRightIn');
setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
1
down vote
up vote
1
down vote
setTimeout or setInterval in javascript might do the trick. for instance:
$( ".overlay-close-button" ).click(function()
{
// problem: $( ".icon_holder" ) selects multiple elements!!!
$( ".icon_holder" ).addClass('magictime tinRightIn');
setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
setTimeout or setInterval in javascript might do the trick. for instance:
$( ".overlay-close-button" ).click(function()
{
// problem: $( ".icon_holder" ) selects multiple elements!!!
$( ".icon_holder" ).addClass('magictime tinRightIn');
setTimeout(function()
{
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2000);
});
answered Nov 27 '14 at 3:19
ymz
2,6681817
2,6681817
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
add a comment |
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
Thanks for your help
– CodeOut
Nov 27 '14 at 13:50
add a comment |
up vote
0
down vote
You would use setTimeout()
to achieve that.
setTimeout(function() {
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2e3);
add a comment |
up vote
0
down vote
You would use setTimeout()
to achieve that.
setTimeout(function() {
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2e3);
add a comment |
up vote
0
down vote
up vote
0
down vote
You would use setTimeout()
to achieve that.
setTimeout(function() {
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2e3);
You would use setTimeout()
to achieve that.
setTimeout(function() {
$( ".icon_holder" ).removeClass('magictime tinRightIn');
}, 2e3);
answered Nov 27 '14 at 3:19
alex
337k166761910
337k166761910
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27162501%2fadd-class-on-click-and-then-remove-class-on-delay%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown