Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    a bit west of pittsburgh
    Posts
    236
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Create an element at script location

    Hello all! I've come back from my long vacation in the land of not-using-javascript!
    Take a look at http://www.pitt.edu/~jrf27/links.html
    Ignore the terrible page. I know it's awful. I'm working on that.

    I made the game on the left side of the page two months ago in C++, and a month ago translated it to TI-BASIC on the TI-83, and then yesterday moved it to javascript. I've goota say, Javascript is the way to go! My headaches of TI-BASIC were instantly relieved when I went back to Javascript.

    Now for my problem. There isn't really a problem in the sense that the game is fully functional, it's more of just something that bugs me. I created the game in hopes of making it as unobtrusive as possible to the page. The entire game uses 3 css classes and one JS Object named bloc. I want the game to generate its own div to live within, which it currenyl does, but I want the div to be name-less and ID-less, so other scripts in any page will not interfere.
    Now to the code:

    Code:
    //Line 28 of bloc.js:
      document.writeln("<div id=\"bloc.par\"></div>");
    
    //Line 32 of bloc.js:
      bloc.par = document.getElementById("bloc.par");
    This is everything that is making me restless. I want that div to be ID-less. How can I create a div, and have it appear in the DOM structure immediately after the script tags that called bloc.gen(), and still be able to reference it later?

    One solution that I came up with was this:
    Code:
    <div><img src="someimage.gif" onload="bloc.par=this.parentNode;bloc.gen();" /></div>
    But it doesn't validate. Yeah yeah yeah. I have a perfectly acceptable solution but I'd rather not use it. Please don't be hatin.

    Thanks!
    Joe

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    a bit west of pittsburgh
    Posts
    236
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Beautiful.
    After writing a few test scripts, I found that FF considers the text within a script tag to be a child of the script, but IE considers the script tag to be the last element in the heirarchy. So...
    Code:
      bloc.par = document.documentElement;
      while (bloc.par.lastChild.nodeName!="SCRIPT") bloc.par = bloc.par.lastChild;
      bloc.par = bloc.par.appendChild(document.createElement("div"));
    Seems to be a working solution. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •