JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 53 sec
Reputation Power: 12
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 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,893 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 2 Days 18 h 35 m 4 sec
Reputation Power: 4192
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

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 53 sec
Reputation Power: 12
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: 10
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: 490 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 1 Day 10 h 56 m 39 sec
Reputation Power: 184
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.
__________________
Gabba Gabba Hey

Reply With Quote
Reply

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

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap