Mon Dec 31, 2012 11:08 pm
<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>
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
Powered by phpBB © phpBB Group.