faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

18 of 21 people (86%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I control style of a DIV-layer I've dynamically written into (NN4+)?

Jul 31st, 2000 23:19
Rey Nuņez, Acebone,


This is not an answer, but an example showing the problem. View this in 
IE and NN to see the difference
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function htmlWrite(idDiv, html){
	if (document.layers){   
		document.layers[idDiv].document.open('text/html')
		document.layers[idDiv].document.write(html)
		document.layers[idDiv].document.close()
	} else {document.all[idDiv].innerHTML = html}
}
function createObj(id){ 
	if (document.layers) { return eval("document" + '[id]' ) }
	if (document.all){ return eval("document.all" + '[id]' 
+ ".style") }
}
function changeText(){ 
	htmlWrite("div1", "If this is NN4, this text has the default 
color and font-face, and I can't change it!")		
	tmpDiv = createObj("div1") 
	tmpDiv.color = "green" 
}
</SCRIPT>
</head>
<body>
This text has the default color and font-face
<div id="div1" style="color : red; position : absolute; top : 30; left: 
10; font-family : courier">This text is red</div>
<BR><BR><FORM><input TYPE="Button" ONCLICK="changeText()" VALUE="Press 
this button"></FORM>
</body>
</html>
------
There are several ways to control the style of a layer dynamically 
written in NN4+.
One is to include html tags directly into the write method, for example:
document.write("<center><font face='Arial' point-size=11>"+ your text 
here +"</font></center>");
Or include an inline style or apply a style class in the write method, 
and use CSS to format the class.