javascript - Trying to get parent id and child id using document.getElementById. Error when trying to select both -
i'm using switch statement alter display of label based on dropdown selection.
i have div id 'titlebox' , nested 'a' id 'generatepid'. in switch statement, when select 'titlebox' using document.getelementbyid, can't find 'generatepid' ,
unable property 'style' of undefined or null reference
when remove line selecting 'titlebox' 'generatepid' found.
<div id="titlebox" class="celltitle" style="width:40px"> <a href="javascript:generatep();" title="xxx." id="generatepid" name= "generatepid">generate</a></div> function onselectcombo(){ var txt = var.getselectedtext(); switch(txt) { case "a": document.getelementbyid('generatepid').style.display='none'; break; case "b": document.getelementbyid('generatepid').style.display='none'; break; case "c": document.getelementbyid('titlebox').innerhtml = "number"; document.getelementbyid('generatepid').style.display='inline'; break; default: document.getelementbyid('generatepid').style.display='inline'; } }
document.getelementbyid('titlebox').innerhtml = "number"; //this line //changes dom <div foo='bar' ...> number </div>, //the below line never work expect. //you should x.innerhtml += "number"; if fits needs document.getelementbyid('generatepid').style.display='inline';
Comments
Post a Comment