PDA

View Full Version : DOM Element error



Deadweight
09-24-2013, 06:13 AM
Problem: Im using DOM element to change the layout of this page; however, the div element is the error


javascript:var ss1 = document.createElement('style');
var def = 'body {background-image: url(http://imageshack.us/m/268/2272/skyorange.jpg);background-repeat:no-repeat; background-color:black;}#topContainer, .top_shadow, .top_bar{display:none;}#fake_links {color: red; position: absolute; top:0; left:0; width:100%; min-width: 1500px height: 50px; border-bottom: 1px solid red; background-color: black; box-shadow: 0px 2px 10px 2px red; -moz-box-shadow: 0px 2px 10px 2px red; -webkit-box-shadow: 0px 2px 10px 2px red;border-bottom: 1px solid white;}#nav{color: white; width: 75%; min-width: 880px; margin: auto; margin-top: 36px; height: 24px;}#nav a{color: none;}#nav a:hover{color: none;}#ul_links li{cursor: pointer;}#ul_links{padding:5px; margin:0; list-style:none;}#ul_links > li{float: left; margin-left: 5px; border:1px solid white; border-bottom: none; padding-left: 7px; padding-right: 7px; padding-top: 2px; padding-bottom: 2px; border-radius: 5px 5px 0px 0px; text-transform: uppercase; font-weight: bold;}#ul_links > li:hover{text-decoration: underline; background-color: red;}#ul_links li > ul{display: none; position: absolute; list-style:none; padding: 0; margin: 0; margin-top: 2px; margin-left: -8px; border: 1px solid white; width: 200px;border-bottom: none;text-transform:none; font-weight: 500;}#ul_links li:hover > ul{display: block;}#ul_links li > ul li{background-color: black; height:20px; line-height: 20px; border-bottom: 1px solid white;padding-left: 1px;}#ul_links li > ul li:hover:before{content: \'> \'; color: red;}#ul_links li > ul li:hover{background-color: #CCC; color: black;}';
ss1.setAttribute("type", "text/css");
var hh1 = document.getElementsByTagName('head')[0];
hh1.appendChild(ss1);
if (ss1.styleSheet)
{ss1.styleSheet.cssText = def;}
else
{var tt1 = document.createTextNode(def);
ss1.appendChild(tt1);}

var main_div = document.createElement('div');
main_div.id = "fake_links";
var final = '<div id="nav"><ul id="ul_links"><li>Overviews<ul><li>Combined</li><li>Production</li><li>Transport</li><li>Troops</li><li>Commands</li><li>Incoming</li><li>Buildings</li><li>Research</li><li>Groups</li><li>Account Manager</li></ul></li><li>Reports<ul><li>All reports</li><li>Attacks</li><li>Defenses</li><li>Support</li><li>Trade</li><li>Miscellaneous</li><li>Forwarded</li><li>Filter</li><li>Block sender</li><li>Publicized reports</li><li>Folders</li></ul></li><li>Mails<ul><li>Mail</li><li>Circular mail</li><li>Write message</li><li>Block sender</li><li>Address book</li><li>Folders</li></ul></li><li>Tribe<ul><li>Overview</li><li>Profile</li><li>Members</li><li>Diplomacy</li><li>Wars</li><li>Noble planner</li><li>Recruitment</li><li>Welcome</li><li>Properties</li><li>Tribal forum</li></ul></li><li>Ranking<ul><li>Tribes</li><li>Players</li><li>Continent Tribes</li><li>Continent Players</li><li>Opponents defeated (tribe)</li><li>Opponents defeated</li><li>Awards</li><li>Wars</li></ul></li><li>Settings<ul><li>Profile</li><li>Settings</li><li>Notifications</li><li>Edit quick bar</li><li>Awards</li><li>Share Internet connection</li><li>Account Sitting</li><li>Logins</li><li>Surveys</li><li>Invite players</li><li>To the mobile version</li><li>Toolbar</li><li>iOS & Android</li><li>Block player</li><li>Voucher codes</li><li>Support ticket</li></ul></li><li>Premium<ul><li>Redeem</li><li>Purchase</li><li>Transfer</li><li>Log</li></ul></li><li>Notebook</li><li>Logout</li></ul></div>';
main_div.innerHTML = final;
document.body.appendChild(main_div);

Error in creating the div element.
Thanks,
-DW

jscheuer1
09-27-2013, 03:02 AM
I'm not getting any errors. Do I have to click on something or do something else to get the error?

Oh and, since it looked like the code was addressing the body, I put it in the body of the page. That might be all you need to do to fix it.

Here's a working demo:

http://home.comcast.net/~jscheuer1/side/demos/tidbits/crazykid69/domh.htm

Deadweight
09-27-2013, 10:19 PM
Its actually a weird error from something else. It would work by itself but doesnt work if i make it a link. I know doesnt make any sense xD

jscheuer1
09-28-2013, 01:26 AM
That might be. I think the error is because, if the script is in the head, there's no body to append to yet. But, as I say, it might be what you're saying.

If you could put up a demo somewhere on the web that shows the error you're talking about and post a link to it here, I can probably pinpoint the issue.