0

Background,

There are some elements where CSS animations needs to be applied. However these CSS needs to be generated on the fly as calculation needs to be done from JavaScript code.

This question clarifies how to dynamically add a CSS. Now the question is, how do I remove or replace a CSS generated following the accepted answer?

Just to be clear, it's nothing to do with removing a class from element. I need to remove it from the page so that animations will stop from elements with class. At some time later I can alter the CSS and re-register class so that associated elements are animated in different way.

9
  • Possible duplicate of Remove CSS class from element with JavaScript (no jQuery) Commented Feb 10, 2017 at 12:41
  • Not a duplicate, this is not about removing CSS from element, but removing class from the page. Commented Feb 10, 2017 at 12:52
  • Then explain yourself better, coz based on the 4 answers that are stating how to remove the class from the element it seems that's what you're asking. Commented Feb 10, 2017 at 12:55
  • Question updated... hope it's clear enough now Commented Feb 10, 2017 at 12:56
  • Okay then so Possible duplicate of How to change/remove css classes definitions at runtime Commented Feb 10, 2017 at 12:56

4 Answers 4

1

document.getElementById('someElementId').className = '';

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. It removes class from the element, I need to remove the class (added dynamically) from the page
0

Edit.

You can remove it from the element's class list

document.getElementById("myelementsid").classList.remove("classname");

3 Comments

If you want to toggle between two class name , use $(#id_name).toggleClass('class_name1 class_name2');
?? I'm answering the OP's question, and without having him to include anything extra (like jQuery that you're using).
Thanks for the answer. It removes class from the element, I need to remove the class (added dynamically) from the page
0

Here you are full documentation to do it with jQuery https://api.jquery.com/removeclass/ with this, you can remove one or more classes

1 Comment

Thanks for the answer. It removes class from the element, I need to remove the class (added dynamically) from the page.
0

If you want to remove the specific style from the page you can do it like the following snippet:

$('link[title=stylesheettitle]').prop('disabled',true);

OR

$('link[title="stylesheettitle"]').remove();

Java Script

var style = document.getElementById('styleID');
style.parentNode.removeChild(style );

3 Comments

Thanks, but I don't want to change element, I need to remove the class, to stop css animations, and add it after an interval with different parameters (for example animation duration / no of pixels transformed/ etc...), and the class does not reside in a style sheet, it's added dynamically (see the linked question)
@LowFlyingPelican what did you try ?
@LowFlyingPelican this what you are looking for: stackoverflow.com/questions/7125453/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.