Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript and CSS not working together 1

Status
Not open for further replies.

Graeme06

Technical User
Jun 6, 2006
60
I'm working on some Javascript embedded in an HTML file that is organized using CSS. Now this seems to make it act really funny. For one thing, the document.write() writes to a new page instead of the current one. (it works fine for the page loading, but if you have an onclick with a document.write(), it doesn't work.

As well I have the code:
function visi(){
document.all['external'].style.visibility = "hidden";
}

Which is supposed to make something ('external') invisible. This works great in a plain HTMl file, but as soon as I paste it into my page with CSS it doesn't do anything.

Is there a way to fix this, possibly replace the "document" in document.write() with another word?

Thanks,
Graeme
 
1) document.write() doesn't work the way you think it does. it writes to the current (or specified) window. if you use it in an onclick event, it will overwrite what you already see on the screen if you're not writing to a new window. you should look into the innerHTML property, and setting it through javascript.

2) the "all" collection is IE-specific - you should not ever use it if you plan to have an audience that may be using a browser other than IE.

3) we can't be any help to you with no specific code. saying "this doesn't work" doesn't really help. give us a link, tell us what doesn't work, etc.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Okay thanks. The problem is that I'm using Firefox to view it. I didn't actually write that section of code, so I didn't know it was IE only.

Anyways, the code:
document.all['external'].style.visibility = "hidden";

Is there a way to rewrite that so it will work with any browser? I know very little Javascript and I don't want to post all of my code because right now it is a mess and confusing (its PHP code actually)

Thanks,
Graeme
 
what is "external"? if it is not the ID of the specified object, make it the ID. then, simply do this:

Code:
document.getElementById("external").style.visibility = "hidden";



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top