473,799 Members | 3,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting styles with InnerHTML!?!

Toxinhead
4 New Member
Hey there guys

I am having a little trouble with InnerHTML as i can't seem to figure out how to set the style of my div tag.....
What im trying to do is that when i rollover pic1 it changes that pic and displays:block and visiblity:visib le....and also changes pic2..

When the webpage is loaded it displays:none and visivlity:hidde n also

Heres my code:

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head>
  3. <script type="text/javascript">
  4. function start(){
  5.     document.getElementById('pic1').src="icons/on1.jpg";
  6.     document.getElementById('aa').innerHTML = "<div style=visibility:visible; display:block;>";
  7.     document.getElementById("bb").innerHTML = "<div style=visibility:hidden; display:none;>";
  8.     document.getElementById("pic2").src="icons/off2.jpg";
  9.      }
  10.  
  11. function one1(){
  12.     document.getElementById('pic1').src="icons/on1.jpg";
  13.     document.getElementById('aa').innerHTML = "<div style=visibility:visible; display:block;>";
  14.     document.getElementById("bb").innerHTML = "<div style=visibility:hidden; display:none;>";
  15.     document.getElementById("pic2").src="icons/off2.jpg";
  16.      }
  17. function two2(){
  18.     document.getElementById('pic1').src="icons/off1.jpg";
  19.     document.getElementById('aa').innerHTML = "<div style=visibility:hidden; display:none;>";
  20.     document.getElementById("bb").innerHTML = "<div style=visibility:visible; display:block;>";
  21.     document.getElementById("pic2").src="icons/on2.jpg";
  22.      }
  23. </script>
  24. <style type="text/css">
  25. #aa  { visibility:hidden; display:none;}
  26. #bb  { visibility:hidden; display:none;}
  27. </style>
  28. </head>
  29. <body onLoad="start()";>
  30.  
  31.  
  32. <div id="aa"> 
  33. bla bla bla bla bla bla
  34. </div>
  35. <div id="bb"> 
  36. da da da da da da da da da da da
  37. </div>
  38.  
  39.  
  40. <img id="pic1" src="icons/off1.jpg" width="50" height="50" onMouseOver="one1()"/><br />
  41. <img id="pic2" src="icons/off2.jpg" width="50" height="50" onMouseOver="two2()"/><br />
  42. </body>
  43. </html>
  44.  
Please help !!!!! i just need to find out how to change the style to invisibility:vi sible and display:block through the innerHTML!!!!

Thanks a million!!
Ricky
Jan 16 '08 #1
8 10112
Delerna
1,134 Recognized Expert Top Contributor
Hey there guys

I am having a little trouble with InnerHTML as i can't seem to figure out how to set the style of my div tag.....
What im trying to do is that when i rollover pic1 it changes that pic and displays:block and visiblity:visib le....and also changes pic2..

When the webpage is loaded it displays:none and visivlity:hidde n also

Heres my code:

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head>
  3. <script type="text/javascript">
  4. function start(){
  5.     document.getElementById('pic1').src="icons/on1.jpg";
  6.     document.getElementById('aa').innerHTML = "<div style=visibility:visible; display:block;>";
  7.     document.getElementById("bb").innerHTML = "<div style=visibility:hidden; display:none;>";
  8.     document.getElementById("pic2").src="icons/off2.jpg";
  9.      }
  10.  
  11. function one1(){
  12.     document.getElementById('pic1').src="icons/on1.jpg";
  13.     document.getElementById('aa').innerHTML = "<div style=visibility:visible; display:block;>";
  14.     document.getElementById("bb").innerHTML = "<div style=visibility:hidden; display:none;>";
  15.     document.getElementById("pic2").src="icons/off2.jpg";
  16.      }
  17. function two2(){
  18.     document.getElementById('pic1').src="icons/off1.jpg";
  19.     document.getElementById('aa').innerHTML = "<div style=visibility:hidden; display:none;>";
  20.     document.getElementById("bb").innerHTML = "<div style=visibility:visible; display:block;>";
  21.     document.getElementById("pic2").src="icons/on2.jpg";
  22.      }
  23. </script>
  24. <style type="text/css">
  25. #aa  { visibility:hidden; display:none;}
  26. #bb  { visibility:hidden; display:none;}
  27. </style>
  28. </head>
  29. <body onLoad="start()";>
  30.  
  31.  
  32. <div id="aa"> 
  33. bla bla bla bla bla bla
  34. </div>
  35. <div id="bb"> 
  36. da da da da da da da da da da da
  37. </div>
  38.  
  39.  
  40. <img id="pic1" src="icons/off1.jpg" width="50" height="50" onMouseOver="one1()"/><br />
  41. <img id="pic2" src="icons/off2.jpg" width="50" height="50" onMouseOver="two2()"/><br />
  42. </body>
  43. </html>
  44.  
Please help !!!!! i just need to find out how to change the style to invisibility:vi sible and display:block through the innerHTML!!!!

Thanks a million!!
Ricky
Ricky, try something like this
var obj=document.ge tElementById('I DOfYourObject')

obj.setAttribut e('align','righ t');
obj.setAttribut e('visibility', 'visible');
Jan 16 '08 #2
Toxinhead
4 New Member
ohok thanks ill give it a shot!
Jan 16 '08 #3
Toxinhead
4 New Member
still dosnt work :( thanks anyway

anyone?
Jan 16 '08 #4
Delerna
1,134 Recognized Expert Top Contributor
OK, then I think this is what you are trying to do


[HTML]<html>
<head>
<script type="text/javascript">
function start(){
document.getEle mentById('pic1' ).src="icons/on1.jpg";
document.all.aa .style.visibili ty = "visible";
document.all.bb .style.visibili ty = "hidden";
document.getEle mentById("pic2" ).src="icons/off2.jpg";
}

function one1(){
document.getEle mentById('pic1' ).src="icons/on1.jpg";
document.all.aa .style.visibili ty = "visible";
document.all.bb .style.visibili ty = "hidden";
document.getEle mentById("pic2" ).src="icons/off2.jpg";
}
function two2(){
document.getEle mentById('pic1' ).src="icons/off1.jpg";
document.all.bb .style.visibili ty = "visible";
document.all.aa .style.visibili ty = "hidden";
document.getEle mentById("pic2" ).src="icons/on2.jpg";
}
</script>

</head>
<body onLoad="start() ">
<img id="pic1" src="icons/off1.jpg" width="50" height="50" onMouseOver="on e1()"/><br />
<img id="pic2" src="icons/off2.jpg" width="50" height="50" onMouseOver="tw o2()"/><br />
<div id="aa">bla bla bla bla bla bla</div>
<div id="bb"> da da da da da da da da da da da</div>

</body>
</html>[/HTML]
Jan 16 '08 #5
Toxinhead
4 New Member
WOWA thanks so much Delerna !!!!!!!!!!!
It works like a dream!!!!

Thanks heaps
Ricky
Jan 16 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. function start(){
  2.     document.getElementById('pic1').src="icons/on1.jpg";
  3.     document.all.aa.style.visibility = "visible";
  4.     document.all.bb.style.visibility = "hidden";
  5.     document.getElementById("pic2").src="icons/off2.jpg";
  6.      }
That won't work in most browsers. Don't use document.all. Use document.getEle mentById instead, so your function becomes:
Expand|Select|Wrap|Line Numbers
  1. function start(){
  2.     document.getElementById('pic1').src="icons/on1.jpg";
  3.     document.getElementById("aa").style.visibility = "visible";
  4.     document.getElementById("bb").style.visibility = "hidden";
  5.     document.getElementById("pic2").src="icons/off2.jpg";
  6.      }
Jan 16 '08 #7
Delerna
1,134 Recognized Expert Top Contributor
Quite right, thanks acoder
in my job, everything i develop only ever gets used in IE so i am a bit weak and a bit lazy in that area
Jan 18 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
No problem. It's never a bad habit to follow standards and then adjust for IE's bugs/quirks. It'll be useful when you're required to support more browsers.
Jan 18 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3569
by: Kerri | last post by:
Sorry, That was a typo. It should read. I have a RequiredFieldValidator This gets rendered out as a <span> I want to set the innerHTML.
5
21634
by: Soren Vejrum | last post by:
I am working on a web-based html editor using MSIE's designmode and iframes. Everything works just fine, but MSIE changes all my relative "a href" and "img src" links (i.e. "/index.asp") to absolute links (i.e. "http://localhost/index.asp") when I set the iframe's innerHTML. This is bad as the links are supposed to be relative. How can I avoid this? Any solutions/suggestions are much appreciated.
1
2893
by: C A Upsdell | last post by:
I have a site where I am setting a style dynamically, using the JS statement: obj.style.backgroundImage = 'url(img/bak_page.jpg)'; where 'obj' is either document.getElementById(id), or document.all, depending on browser support. This works just fine, with just one small problem: I want to set the style ONLY for screen media, not for printer media; the above statement appears to
4
6554
by: RobG | last post by:
I know you aren't supposed to use innerHTML to mess with table structure, but it seems you can't use it just after a table without damaging the containing element. I added a table to a div using createElement methods, then added a bit of extra text using innerHTML, only to find most of the attributes removed from the table. Below is a script that calls the same code to add a table inside a div. It adds an onclick to the div and...
3
1586
by: sagar | last post by:
Hello everyone, I am developing a AJAX based IM application. I use javascript to dynamically generated small windows using nested <div> within the web-page. I use the following ways to set attributes & styles e.g. .style.height=10; for styles .setAttribute("id","outer") for attributes
17
34726
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works fine. However the HTML have a SCRIPT tag that the browser should process, but
4
1651
by: Mike | last post by:
Hello, I am trying to change the style(Position of an image) with a function.This code worked a month ago and I dont know what I changed I'm only showing the relevant code. One image is superimposed on another. -------------------------------------------------------------------- <script type="text/javascript"> function changenote(element) { alert ("This Function is being Called");//Checking to see if the
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.