javascript - Document.getElementById issue (accessing width attribute) -
i've tried adding .style, .style.width, , .style.width.value parts of javascript, no avail far.
essentially, 2 things.
to alert of value of
50px"animate" button click, runsanim8function. in other words, wantwidthofdiv.in second set of code (
anim82), want able set/changewidthvia button click. add10pxwhen button clicked. first, need access variable though,width, before can change anything.
html
<div id="maintxt">dag!</div> <form name="myform" action="" method="get"> <input type="button" name="button" value="animate" onclick="anim8(this.form)"> <input type="button" name="button" value="animate2" onclick="anim82(this.form)"> css
#maintxt{width:60px;} javascript
var divalert; var divsize; function anim8(form) { divalert=document.getelementbyid("maintxt"); alert(divalert); } function anim82(form) { divsize=document.getelementbyid("maintxt"); divsize.style.width=parseint(divsize.style.width)+10+'px'; }
try this
function anim82(form) { divsize=document.getelementbyid("maintxt"); var width=divsize.offsetwidth + 100; divsize.setattribute("style","width:"+ width +"px") }
Comments
Post a Comment