In this post you will learn how to remove class from a div at runtime using jQuery. As far as removing div at runtime is concerned, we are to deal with two functions:
jQuery.toggleclass() and jQuery.switchclass() functions.
jQuery.toggleclass():
This function is dependent on class’s presence and value of the state argument. It is used to remove or add one or more classes from each matched element in the set of element.
jQuery.switchclass():
This function has the feature to animate all style changes. Otherwise it does the same task as JQuery.toggleclass().
Another way to remove class is coding in JQuery .You can do this by understanding this example:
function ChangeClassName() {
$(‘#div1’).removeClass(‘active’);
}
</script>
<input id=”Button1″ type=”button” value=”button” onclick=”ChangeClassName();” />
<div id=”div1″ class=”active”>
<a href=”#”>Click Me</a>
</div>
Please check the code given below. This will help.
jQuery Code
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”Generator” content=””>
<meta name=”Author” content=””>
<meta name=”Keywords” content=””>
<meta name=”Description” content=””>
<title>Document</title>
<script src=”jquery.js”></script> // Give path of jQuery Latest file
</head>
<body>
<div id=”addClassHere” class=”selected”>Hello Garry</div>
</body>
<script>
$( “#addClassHere” ).removeClass( “selected” );
</script>
</html>
On page load, this class will automatically be added to the div with id “addClassHere
[…] To remove class from a div at runtime using jQuery It's only fair to share… In this post you will learn how to remove class from a div at runtime using jQuery. Please check the code given below. […]