---
title: "How to add / remove CSS class dynamically"  
description: "How to add / remove CSS class dynamically"  
author: "marcel ethan"  
published: 2013-04-16  
updated: 2013-04-16  
canonical: https://www.mindstick.com/forum/762/how-to-add-remove-css-class-dynamically  
category: "css-css3"  
tags: ["css-css3"]  
reading_time: 1 minute  

---

# How to add / remove CSS class dynamically

Hi Everyone!\
I want to [add and remove](https://www.mindstick.com/forum/160516/how-to-add-and-remove-a-column-in-datatable-in-dot-net-using-c-sharp) [css](https://www.mindstick.com/forum/514/background-gradient-ie7-css-problem) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) dynamically using [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) or jquery in html.\
please help me!\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Marcel!\
You can do as below\

```
<div id="div1" class="getid">       </div><div id="div2" class="getid">        </div><style type="text/css">        .setpos        {            position: relative;            z-index: 1;        }    </style><script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script><script type="text/javascript">        $(document).ready(function () {            jQuery(".getid").click(function () {                jQuery("#div1").removeClass("setpos");                jQuery("#div2").removeClass("setpos");                var getid = jQuery(this).attr('id');                jQuery("#" + getid).addClass("setpos");            });        });</script>
```


---

Original Source: https://www.mindstick.com/forum/762/how-to-add-remove-css-class-dynamically

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
