jQuery toggleClass addClass removeClass Examples

jQuery toggleClass addClass removeClass Examples

In this Post We Will Explain About is jQuery toggleClass addClass removeClass Examples With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to addClass, removeClass, hasClass and toggleClass in jQueryExample

In this post we will show you Best way to implement jQuery addClass(), removeClass(), toggleClass() example, hear for jQuery Add and Remove CSS Classeswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  how to change colour of blue highlight on select box dropdown?

jQuery addClass() Method Example




$(document).ready(function(){
    $("button").click(function(){
        $("span:first").addClass("customdata");
    });
});


.customdata {
    font-size: 200%;
    color: green;
}




<h1>This is a First heading For : Pakainfo.com</h1>

<span>This is a my first POST.</span>
<span>This is second one another POST.</span>

<button>Submit</button>



How to remove class from all elements jquery

<div id="menuItems"> 
 <ul id="contentLeft" class="stock_move"> 
 <li class="sep">Shakes and Floats</li> 
 <li id="997" class="highlight"><a href="#"><strong>$41.00</strong><b>Vanilla</b>     </a></li> 
 <li id="998" class="highlight"><a href="#"><strong>$41.00</strong><b>Peanut Butter</b></a></li> 
 <li id="999" class="highlight"><a href="#"><strong>$41.00</strong><b>Combo</b></a></li> 
 <li id="900" class="highlight"><a href="#"><strong>$41.00</strong><b>Chocolate</b></a></li> 
 <li id="901" class="highlight"><a href="#"><strong>$41.00</strong><b>Strawberry</b></a></li> 
 <li id="903" class="highlight"><a href="#"><strong>$41.00</strong><b>Banana</b></a></li> 
 <li id="904" class="highlight"><a href="#"><strong>$41.00</strong><b>Root Beer Float</b></a></li> 
 <li id="905" class="highlight"><a href="#"><strong>$41.00</strong><b>Espresso</b></a></li> 
 </ul>
 </div> 
 
 $(".stock_move li").removeClass("highlight");

jQuery toggleClass to Switch Between Classes

index.html

<p id="mypargraph1" class="toggle red">live</p>
<p id="mypargraph2" class="toggle green">w3free</p>
<p id="mypargraph3" class="toggle green">itfiddle</p>
<p id="mypargraph4" class="toggle green">donkey</p>
<button>Toggle classes for first two p elements</button>

index.js
$('button').click(function(){
  $('.toggle').toggleClass('red green');
});

CSS
.red{ color:red; }
.green{ color:green; }
.blue{ color:blue; }

Example

Read Also:  jQuery Remove Class From HTML Elements Example

I hope you have Got What is Add Class, Remove Class or Toggle Class using jquery And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Angular 6 Searching Sorting Pagination Tutorials
  2. Read Also:  jQuery toggleClass Method with Example
  3. Read Also:  Capture Webcam Image with PHP and jQuery
  4. Read Also:  jQuery Dynamically addClass and removeClass
  5. Read Also:  Dynamically addClass CSS click using jQuery
  6. Read Also:  remove class jquery
  7. Read Also:  Validate CKEditor Fields Using JQuery validation
  8. Read Also:  Remove Duplicate Objects from Array Jquery Example
  9. Read Also:  multiple drop down list in php using ajax
  10. Read Also:  Income Tax Saving Investments Tax Planning