Closed Thread Icon

Topic awaiting preservation: Setting Float via JS Pages that link to <a href="https://ozoneasylum.com/backlink?for=27449" title="Pages that link to Topic awaiting preservation: Setting Float via JS" rel="nofollow" >Topic awaiting preservation: Setting Float via JS\

 
Author Thread
bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-06-2006 19:41

My google-fu is weak today and I can't find an answer to this.

Here I'm using code like so to create a div

code:
<script language="javascript">
window.onload = creater;
function creater() {
	newElm = document.createElement('div');
	var exitLink = document.createElement('a');
	// exitLink.style.float = 'right';
	exitLink.setAttribute('href','javascript:void(0)');

	exitLink.appendChild( document.createTextNode('x') );
	exitLink.style.float = 'right';
	exitLink.style.padding = '1px';
	exitLink.style.fontSize = '8px';
	exitLink.style.border = '1px solid #032462';
	exitLink.style.display = 'block';
	exitLink.style.margin = '2px';
	exitLink.style.width = '10px';
	exitLink.style.textDecoration = 'none';
	exitLink.style.textAlign = 'center';
	
	newElm.style.width ='100px';
	newElm.style.backgroundColor = '#ccc';
	newElm.appendChild( exitLink );
	newElm.appendChild( document.createTextNode('This is a whole bunch of text text') );
	document.body.appendChild( newElm );
	}
</script>



But my float attribute is not getting set (I can see this in the DOM inspector). Also I get a warning about float being a reserved word ( which it is I understand that).

So is there some trick to setting the float property ivia JS?



.:[ Never resist a perfect moment ]:.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 02-06-2006 21:40

What if you set the whole exitLink.style in one pass ? Via exitLink.style = 'float:right; padding:1px ... '; or exitLink.setAttribute( 'style', 'float:right; padding:1px ... ' );

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-06-2006 22:46

Ah the first didn't work, the setAttribute did however.



.:[ Never resist a perfect moment ]:.

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

posted posted 02-07-2006 13:48

Most things that are reserved words in one language are referred to by appending the originating language to it.

For example:
CSS: float --> JS: cssFloat
HTML: label for --> JS: htmlFor

There are a few exceptions though, notably the ones that are used by more than one language.

CSS&HTML: class --> JS: className

--
var Liorean = {
abode: "http://web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

(Edited by liorean on 02-07-2006 13:48)

Scott
Paranoid (IV) Inmate

From: schillmania.com
Insane since: Jul 2002

posted posted 02-12-2006 19:49

I've found that sometimes setting attributes work (or don't) before/after an append to the document. Kind of wacky.

Also, to get around a lot of this you could just append a CSS ID or class name to the element, and have it inherit the visual style from there.

joelee
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2005

posted posted 02-14-2006 03:28

b

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 02-14-2006 07:39

c


Justice 4 Pat Richard

« BackwardsOnwards »

Show Forum Drop Down Menu