Click to See Complete Forum and Search --> : Set Width as %


bazjones
11-12-2004, 10:51 AM
Hey ppl

Does anyone know if it is possible to set the width of an item as a percentage using javascript?
As i have tried it but when i set it to a % the item does not show up?
e.g

when i set it like this it shows and works fine:

'width': 155,

but when i set it like this it does not even appear on my webpage??

'width': 60%,

Any ideas why this is and how to get around it??

Thanks

Baz

Exuro
11-12-2004, 11:36 AM
The width attribute should be set as a string with units included:
document.getElementById("myElement").style.width = "50%";

Jona
11-12-2004, 11:37 AM
<p onclick="this.style.width='30%';" style="width: 80%">Gig ver haf nak
heg reo nel yeu nongui. Wit dofnuobaa sao kulcab lik zuylai xet cab ziw
mil coeteq vuuver lai tutroqroqxas pupmunkei xuwcid rurpupjukpin kij cid
cab pupxuwgui. Lolxuwbaa huj. Cab war pin yowbodcuf. Qophuj. Lolbic siq
cab yeu war wes cab lik zev sao mek fogmil gohzuylolnel kei mil qen
lumwouwouyiv votlik pem roqkah die poobeb quqver cec nak jojnim poomil
cab tap cab lumlai yiv xuwfad cec bic jag coelej kij sao hih wuvlej
vuututmek yiv gui. Nim rurgae wuvfuh. Dac fogyiv kij susxuwhoiyowpal cab
tutqam sao wes pem dug. Mil ziw wit hoiyiv nonqio beb sornak sorfuh.
Fogdoflumnuoyuxxiu cuf. Dofsao gef ver bic cid bue. Rip foggig tir xet
nel gohmunyiv zev hih lolbic cid wuvcoeyat cuf. Jukquqquqhih lej ziw
tosfif yuxteq nuofogkei woujii qopkij jojcec noncid pupwar jii tap
roqgig yiv rip lej jag ran qio heg tir siq kei qen wes fad qam wit
momsusheg woudoflai yat reo jukheg gef teq sorxas zoxcab xiu yowzuynel
hoitir jeh dug. Nak vuuded reo tuttap hoigohmunsornim qopmek xiu xiu
dug. Pal beb yeu jukgef quqxas sao lumqen huj. Kij kokhoisep jag pem sep
wes poorip haf lai vis hoiteq xiu ran die tutcuf. Dofsep susxet votbue.
Nonwuvrurkokgui. Nuoyiv reo yeu gohxet sao roqpem zau sep tutmomhaf.</p>


Edit: Didn't see Exuro's reply.