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.

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>

 

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.

Guest
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.

Loading...
×
×
  • Create New...