PHPremote 0 Posted May 20, 2019 Report Share Posted May 20, 2019 Apparently, I have a line break within my innerHTML in a span tag with id=accountPanelTxt . I have to add a line break in a variable I am testing, as shown here. Quote if (x == '\ntrue') { This is the resulting HTML, before the username innerHTML is altered: <span id="accountPanelTxt"> true</span> <span id="usernameTxt"> morenuts3</span> This is the Javascript: <script> alert("got here1b"); alert(document.getElementById("accountPanelTxt").innerHTML); loggedIn = document.getElementById("accountPanelTxt").innerHTML; alert("logged in: "+loggedIn); alert(document.getElementById("usernameTxt").innerHTML); var userName = document.getElementById("usernameTxt").innerHTML; alert("userName: "+userName); alert(document.getElementById("accountPanel").innerHTML); x = document.getElementById("accountPanelTxt").innerHTML; alert("x: "+x); z = 'true'; alert("z: "+z); y =''; menuTxt = ''; if (x == '\ntrue') { y = "T"; menuTxt = '<div class="dropdown"><button class="dropbtn">'+userName+'</button><div class="dropdowncontent"><a href="#">My Account</a><a href="#">My profile</a><a href="#">Profile Settings</a><a href="#">Notifications</a><br><a href="logout.php">Logout</a></div></div>'; } else { y= "F"; menuTxt = '<a href="indextemplate.php" id="loginlink">Login</a></td><td><a href="indextemplate.php" id="loginlink">Register</a>'; } alert(y); alert(menuTxt); document.getElementById("accountPanelTxt").innerHTML = menuTxt; alert("got here2b"); </script> Quote Link to post Share on other sites
dsonesuk 913 Posted May 20, 2019 Report Share Posted May 20, 2019 You are inserting invalid block elements (div), also invalid td , as it should be within a tr element. This will cause the browser to render these invalids element correctly creating extra empty elements causing the problems you are experiencing. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.