How to add / remove CSS class dynamically

Total Post:104


 2326  View(s)
Rate this:
Hi Everyone!

I want to add and remove css class dynamically using javascript or jquery in html.

please help me!

Thanks in advance!
  1. Re: How to add / remove CSS class dynamically

    Hi Marcel!

    You can do as below

    <div id="div1" class="getid">       
    <div id="div2" class="getid">        
    <style type="text/css">
                position: relative;
                z-index: 1;
    <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 () {
                    var getid = jQuery(this).attr('id');
                    jQuery("#" + getid).addClass("setpos");

      Modified On Mar-30-2018 12:11:14 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.