Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically add style info to DIV

Status
Not open for further replies.

chetFinster

Programmer
Joined
Mar 3, 2005
Messages
6
Location
US
Here's the problem:

A program I use creates the DIV tags dynamically, but doesn't add a 'filters' attribute, which I need to use to adjust the alpha of objects on the fly (trans in and out).

The following is the last line as the program writes it:
**** this.div += ' border=0 >'+divEnd+'\n' ***

I comment it out and replace it with:
*** this.div += ' border=0 style="filter:alpha(opacity=100);z-index:60" class = "drag">'+divEnd+'\n' ***

(ignore all asterisks)

My replacement works fine, but I'd rather not have to crack open the code. I'd rather add the filter attribute dynamically.

Struggled with this for a while so I'm asking for some help here (I've tried *** thisVariable.style += "filter:alpha(opacity=100)" *** but the problem seems to be that 'style' hasn't been declared in the DIV tag)

Thanks in advance

Peter

 
I must be missing something somewhere.

If I add my replacement string when the DIV is initially written, then a value for:
*** alert(document[newObject].filters.alpha.opacity); ***

is 100.

If I try to simply set
*** thisVariable.style = "filter:alpha(opacity=10)" ***
and then check the opacity value again I am alerted that document[newObject].filters.alpha.opacity is NULL or not an object.

Have I clearly explained what I am attempting to do? thanks for the help so far---
 
Code:
thisVariable.style.filter = "alpha(opacity=10)";


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
OK - one more time at the risk of being redundant.

In the DIV tag, the attribute style does not exist. It is never written into the DIV tag, so the filter:alpha.opacity value can not be set.

I don't believe you are saying that the attribute gets dynamically written when a value is assigned to it, are you?

What I am asking, perhaps in a badly stated way, is:

'Can I add these attributes dynamically to the DIV tag if they do not exist initially?

Can I 'concatenate' them to the DIV tag. Can I add 'style.filter'?

I already know I can set the value after it exists in the DIV tag. I need to know if I can ADD it after the DIV has been written.

Apologies if unclear earlier.
 
YES, you can set the attribute value after the DIV tag has already been written (but not before). It doesn't matter whether it has already been set or not. You can't READ one that hasn't been set, but you CAN SET it.

You seem to be getting the syntax between setting an attribute in the tag, setting an attribute in CSS, and setting an attribute in javascript. Here's the difference:
Code:
[b]HTML TAG:[/b]
<div id='theDiv' style="filter: alpha(apacity=10);">
[b]JAVASCRIPT:[/b]
document.getElementById('theDiv').style.filter = "alpha(opacity=10)";
[b]CSS:[/b]
DIV { filter: alpha(apacity=10); }


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
So if the DIV tag looks like this:
<div id= "image5094"><a name = "image5094anc"><img name = "image5094Img" src ="images/see.gif' alt="See" width=142 height=92 border=0></a></div>

Then I can fun a function that does this:
document.getElementById('image5094').style.filter = "alpha(opacity=10)";
and it will work? Even if style.filter is never declared in the original div tag?

If so - great. If not??
 
YES!{/b]


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top