|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Exerting style on innerHTML object
I am creating span tags on the fly in javascript. Each span is assigned an id. Once the script is done looping it prints this info to the screen. However, after the fact of printing - going to be based off of user input, I want to exert style(ie boldness, font-size, font-color) on a javascript generated tag: For example:
Code:
document.getElementById("test").innerHTML = "<span id=\"test\">SomeTest</span>";
document.getElementById("test").style.color = "#DDDDDD";
I've tried the above and doesn't seem to be working. Any suggestions? Last edited by askjoe : March 24th, 2006 at 04:09 PM. |
|
#2
|
||||
|
||||
|
IDs should be unique. You could use a class instead.
Class and ID Selectors When should I use a class and when should I use an ID? I don't think we can offer more help without seeing more of your code.
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. Check out my blog. |
|
#3
|
||||
|
||||
|
Quote:
I have tried it both with id and class - I get the same result - no style applied to the tag - in both mozilla and IE I get the following error: document.getElementById("test") has no properties when I run the above code Last edited by askjoe : March 24th, 2006 at 04:21 PM. |
|
#4
|
|||
|
|||
|
you first need a HTML tag with the id "test" before you can grab it with "document.getElementById".
|
|
#5
|
|||
|
|||
|
Assuming the original object you are creating your new span under, is, well let's say div, your output will be:
Code:
<div id="test">"<span id=\"test\">SomeTest</span></div> Since id has to be unique, your logic ain't right.
__________________
"Sir, if you were my husband, I would poison your drink." --Lady Astor to Winston Churchill "Madam, if you were my wife, I would drink it." --His reply View Interactive Oy |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Exerting style on innerHTML object |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|