Click here to Skip to main content
15,914,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I want to show some text on backgroung image i have set. The code is showing text but it hides the button. I want the button remain.
Can anyone help me ???
Thanks in advance.
<html>
<head>
<script type="text/javascript">
function changeStyle()
{document.write(""+""+""+"ABC");
document.body.Image="url(bgdesert.jpg)";
}
</script>
</head>
<body>
<input type="button"  önclick="changeStyle()" value="Set background-image" />
</body>
</html>
Posted
Comments
Prerak Patel 6-Apr-11 1:49am    
use pre tag for the codes to make question more readable.

1 solution

Maybe this will help:

<html>
<head>
<script type="text/javascript">
function changeStyle()
{
var elem = document.getElementById("text");
elem.innerHtml= ""+""+""+"ABC";
document.body.Image="url(bgdesert.jpg)";
}
</script>
</head>
<body>
<div id="text"></div>
<input type="button" önclick="changeStyle()" value="Set background-image" />
</body>
</html>
 
Share this answer
 
Comments
Farah Siraj 6-Apr-11 3:58am    
I have used your suggestion for innerHtml in the following code but it is not working.Any other suggesstion please???
<pre>
<html>
<head>
<script type="text/javascript">
function changeStyle()
{
var elem = document.getElementById("tower");
elem.innerHtml= "ABC";

}
</script>
</head>
<body>
<img id="tower" src="Towers.jpg" width="100%" height="93%" />
<input type="button" önclick="changeStyle()" value="Set background-image" />
</body>
</html>
</pre>
jim lahey 6-Apr-11 4:09am    
You're trying to set text on an image.. I don't think that will work. show the image as a background in a <div> and set the text on the div.
Farah Siraj 6-Apr-11 5:37am    
If i'm using background image via css then what happens that ialthough i have set image height and width by 100% but it shows the original image heigth and width which is very less.
How can i set heigth and width in this code.
Please help me to fix it.
<pre>
<html>
<head>
<script type="text/javascript">
function changeStyle()
{

}
</script>
</head>
<body>
<div style="background-image:url(Towers.jpg);
background-repeat:no-repeat;
width:100%;
height:100%;">
</br></br></br></br></br></br>
LOADING...

</div>
<p>

<input type="button" önclick="changeStyle()" value="Set background-image" />

</body>
</html>
</pre>

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