Total members 11895 |It is currently Fri Dec 27, 2024 12:17 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Add and Remove CSS classes to html tag dynamically
Code:

<html>
<
head>
<
title>Change CSS of Element, Add new CSS/ Remove CSS class
/ Toggle </title>

<!--
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
 Note you can download the JQuery package instead of using Google version. --> 
<script src="jquery-1.8.3.js"></script>
<script>
$(document).ready(function(){
  $("button#b1").click(function(){
    $("#p1").addClass("class1 class2");
  });
  
    $("button#b2").click(function(){
    $("#p2").removeClass("class3");
  });
  $("button#b3").click(function(){
  $("#p2").toggleClass("class3");
}); 
});
</script>
<style type="text/css">
.class1
{
font-size:xx-large;
font-weight:bold;
background:#F25201;
height:400px;
width:400px;
}
.class2
{
text-align:center;
text-decoration: underline;
color:blue;
}
.class3
{
color:red;
background:#52F201;
height:400px;
width:400px;
}


</style>
</head>
<body>

<p id="p1">Write your paragraph here, after pressing the button this paragraph will be affected by CSS classes.</p>
<p id="p2" class="class3">CSS affect will be removed from this paragraph</p>
  
<br>
<button  id="b1">Add classes to first paragraph element</button>
<button   id="b2">Remove classes from second paragraph element</button>
<button   id="b3">Toggle class for second paragraph element</button>
</body>
</html>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Add and Remove CSS classes to html tag dynamically
 Remove HTML element or Delete its content     -  
 about classes     -  
 How to create and use classes in C++     -  
 how do i create the classes XX and YY?     -  
 Remove Indentation     -  
 Abstract Classes in jsp     -  
 Remove all the vowels from a string     -  
 Wrapper classes use in java     -  
 Calling Functions Dynamically     -  
 Dynamically Create Image     -  



Topic Tags

JQuery Content
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com