Jump to content

line break added within innerHTML?

Recommended Posts

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.


if (x == '\ntrue') {


This is the resulting HTML, before the username innerHTML is altered:

<span id="accountPanelTxt">

<span id="usernameTxt">


This is the Javascript:

alert("got here1b");
loggedIn = document.getElementById("accountPanelTxt").innerHTML;
alert("logged in: "+loggedIn);

var userName = document.getElementById("usernameTxt").innerHTML;
alert("userName: "+userName);


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>';
document.getElementById("accountPanelTxt").innerHTML = menuTxt;

alert("got here2b");


Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...