JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 24th, 2006, 03:50 PM
askjoe's Avatar
askjoe askjoe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 491 askjoe User rank is Corporal (100 - 500 Reputation Level)askjoe User rank is Corporal (100 - 500 Reputation Level)askjoe User rank is Corporal (100 - 500 Reputation Level)askjoe User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 2 h 7 m 21 sec
Reputation Power: 8
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.

Reply With Quote
  #2  
Old March 24th, 2006, 04:09 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 23rd Plane (16000 - 16499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,407 Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 1 Day 14 h 19 m 23 sec
Reputation Power: 1780
__________________
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.

Reply With Quote
  #3  
Old March 24th, 2006, 04:11 PM
askjoe's Avatar
askjoe askjoe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 491 askjoe User rank is Corporal (100 - 500 Reputation Level)askjoe User rank is Corporal (100 - 500 Reputation Level)askjoe User rank is Corporal (100 - 500 Reputation Level)askjoe User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 2 h 7 m 21 sec
Reputation Power: 8
Quote:
Originally Posted by Kravvitz



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.

Reply With Quote
  #4  
Old March 24th, 2006, 06:28 PM
CrAzY_J CrAzY_J is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 133 CrAzY_J User rank is Corporal (100 - 500 Reputation Level)CrAzY_J User rank is Corporal (100 - 500 Reputation Level)CrAzY_J User rank is Corporal (100 - 500 Reputation Level)CrAzY_J User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 1 h 43 m 16 sec
Reputation Power: 6
you first need a HTML tag with the id "test" before you can grab it with "document.getElementById".

Reply With Quote
  #5  
Old March 24th, 2006, 08:09 PM
jst666 jst666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Kurvi
Posts: 430 jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level)jst666 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 2 h 2 m 21 sec
Reputation Power: 164
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Exerting style on innerHTML object


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT