Jump to content

line break added within innerHTML?


PHPremote
 Share

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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...