Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to remove and then again apply background image using java script and in addition changing color of text and background also.



XML
<html>
<head>
<title>Text Color Change</title>
<script type="text/javascript" src="JScript.js"></script>
</head>
<body>
<div id="bg">
</div>
<div id="b1">
<h1>This is for Text Color and background color change</h1>
<button id="Btn1" type="button" onclick="changecolor()">
Click Me to change text-color</button>
</div>
<div id="b2">
<button type="button" onclick="changeBackground()">
Change the background </button>
</div>
<div align="right">
<button type="button" onclick="clearimage()">
Remove Image</button>
</div>
</body>
</html>
Posted

Use jQuery for css manipulation
http://api.jquery.com/css/[^]
 
Share this answer
 
Comments
Member 9438848 16-Nov-12 0:01am    
no, have to use only javascript and css only,jquery not to be used.
how to remove and then again apply background image using java script and in addition changing color of text and background also.

JavaScript
<script type="text/javascript" src="jquery-1.8.2.js"></script>

<script type="text/javascript">

//using jQuery

$(function(){
$("#changeColor").click(function(){
$(".container").css("color","#3399ff");//setting property one by one
});
$("#remImage").click(function(){
$("#myImg").toggle();
//you can use show() and hide() method
});
$("#changeback").click(function(){
$(".container").css({,"font-size":"10px",});//setting properties in json format
//you can use show() and hide() method
});
});

//without jQuery.
function changecolor(){
document.getElementById('container').style.color="#334499";
}
function clearimage(){
document.getElementById('myImg').style.display='none';
}
function changeBackground(){
document.getElementById('container').style.backgroundColor="yellow";
}
</script>


HTML
<body>
<div class="container" style="width:700;float:left" id="container">
<img src="http://flickholdr.com/200/200/1" id="myImg"/>
<h1>This is for Text Color and background color change</h1>
</div>
<div class="buttonDiv" style="width:300;float:right">
<button type="button"  önclick="changecolor()" id="changeColor">
Click Me to change text-color</button><br />
<button type="button"  önclick="clearimage()" id="remImage">
Remove Image</button><br />
<button type="button"  önclick="changeBackground()" id="changeback">
Change the background </button>
</div>
</body>
 
Share this answer
 
v2
Comments
Member 9438848 16-Nov-12 0:09am    
usage of jquery restricted, only javascript and css.
deepak.m.shrma 16-Nov-12 1:03am    
bro i have updated code. please check it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900