Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-28-2008, 07:42 PM   PM User | #1
dragon6158
New Coder

 
Join Date: Jan 2008
Posts: 93
Thanks: 30
Thanked 0 Times in 0 Posts
dragon6158 is an unknown quantity at this point
Changing font style to match parent font style

Hello,
I am trying to change the font style of var element to match the font style of whatever i am inserting the var element into. This element could be a header, list item, paragraph or eny other kind of element. Any help in doing this would be appreciated because all I get when I try to access the parent element is undefined or null.

Thanks,
Don
dragon6158 is offline   Reply With Quote
Old 04-28-2008, 07:49 PM   PM User | #2
mrhoo
Regular Coder

 
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
mrhoo will become famous soon enoughmrhoo will become famous soon enough
Quote:
var element to match the font style
do you mean a <var> element, and do you mean font-style?

if so, use css: var{font-style:inherit}
mrhoo is offline   Reply With Quote
Old 04-28-2008, 07:54 PM   PM User | #3
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
i believe you're looking for something like this

myElement.style.fontStyle = oldElement.style.fontStyle;

or in better context

Code:
 
function doAddElem(prnt, objType, contents){
var fntStyl = prnt.style.fontStyle;
var obj = document.createElement(objType);
obj.innerHTML = contents;
obj.style.fontStyle = fntStyl;
prnt.appendChild(obj);
}
__________________
-Mike
"Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender
mjlorbet is offline   Reply With Quote
Old 04-28-2008, 07:54 PM   PM User | #4
dragon6158
New Coder

 
Join Date: Jan 2008
Posts: 93
Thanks: 30
Thanked 0 Times in 0 Posts
dragon6158 is an unknown quantity at this point
Something like this:

Code:
function setVarStyle(){
	var varcopy = document.getElementsByTagName("var");
	var varparent;
	if (varcopy.length < 1) return false;
	for (var i = 0; i < varcopy.length; i++){
		varcopy[i].css{font-style:inherit};
	}
}
?
dragon6158 is offline   Reply With Quote
Old 04-28-2008, 07:59 PM   PM User | #5
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
Quote:
function setVarStyle(){
var varcopy = document.getElementsByTagName("var");
var varparent;
if (varcopy.length < 1) return false;
for (var i = 0; i < varcopy.length; i++){
varcopy[i].css{font-style:inherit};
}
}
bolded line should read

varcopy[i].style.fontStyle = "inherit";
__________________
-Mike
"Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender
mjlorbet is offline   Reply With Quote
Old 04-28-2008, 08:09 PM   PM User | #6
dragon6158
New Coder

 
Join Date: Jan 2008
Posts: 93
Thanks: 30
Thanked 0 Times in 0 Posts
dragon6158 is an unknown quantity at this point
It still comes back as italics regardless of the font-style of the parent. Thanks for the suggestion.
dragon6158 is offline   Reply With Quote
Old 04-28-2008, 08:11 PM   PM User | #7
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
EDIT: my mistake, i thought you said bolded for some reason
__________________
-Mike
"Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender
mjlorbet is offline   Reply With Quote
Old 04-28-2008, 08:15 PM   PM User | #8
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
Code:
 
function setVarStyle(tgnm){
var varcopy = document.getElementsByTagName(tgnm);
if (varcopy.length < 1) return false;
for (var i = 0; i < varcopy.length; i++){
varcopy[i].style.fontStyle = varcopy[i].parentElement?varcopy[i].parentElement.style.fontStyle:"normal";
}
}
pass in the name of the tag to the function, ie

setVarStyle("div");
__________________
-Mike
"Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender
mjlorbet is offline   Reply With Quote
Old 04-28-2008, 08:16 PM   PM User | #9
dragon6158
New Coder

 
Join Date: Jan 2008
Posts: 93
Thanks: 30
Thanked 0 Times in 0 Posts
dragon6158 is an unknown quantity at this point
Apparently the var element is italicized by default and what my supervisor wants me to do is set the font attributes based on what the parent has. With doing nothing, the var element inherits everything from the parent but the font-style. I can set the font-style by hard coding it but I am having problems accessing the font-style property of the parent.
dragon6158 is offline   Reply With Quote
Old 04-28-2008, 08:19 PM   PM User | #10
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
the code you posted before never actually references the parent element, just use the last post and pass in "var"


setVarStyle("var");
__________________
-Mike
"Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender
mjlorbet is offline   Reply With Quote
Users who have thanked mjlorbet for this post:
dragon6158 (05-05-2008)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:43 AM.


Advertisement
Log in to turn off these ads.