javascript - Cannot read property style of null issue -


i've made function gives error

cannot read property 'style' of null

can please me figure out problem is?

function cade() {     var = document.getelementbyid(this.id).style.top;     = + 100;     document.getelementbyid(this.id).style.top =  a+'px'; } cade.call(document.getelementbyid("p")); 

while function works correctly, styling on element prevents doing move it. adding position: absolute or along lines make move correctly.

since you're passing element this, don't need fetch again using getelementbyid. reference have valid, can simplify code like:

function cade() {    var = this.style.top;    = + 100;    this.style.top = + 'px';  }  cade.call(document.getelementbyid("p"));
div#p {    position: absolute;  }
<div id="p">this text.</div>


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -