CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: innerHTML in head

    Isn't this a more clean and general way to do it?
    Code:
    function addScript(window_number) {
        var prefix = "window_" + window_number + "_";
        var wone = $(prefix + "wone");
        var container = wone.getParent();
    
        var fx = new Fx.Style(wone, "opacity").start(0, 1);
    
        wone.makeResizable({ handle: $(prefix + "botright"), container: container });
        $(prefix + "inner").makeResizable({ handle: $(prefix + "botright"), container: container });
        wone.makeDraggable({ handle: $(prefix + "handle"), container: container });
        wone.style.height = "257px";
    }
    Then use it like so:
    Code:
    // Add script to windows #1 and #2.
    addScript(1); addScript(2);

  2. #17
    Join Date
    May 2002
    Posts
    10,943

    Re: innerHTML in head

    Quote Originally Posted by Kovo88
    using eval() maybe?
    Don't ever use eval() unless you are 100% in control of what it is about to do. It is very powerful, but sometimes too powerful. It can and will execute anything passed to it!
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #18
    Join Date
    Sep 2007
    Posts
    28

    Re: innerHTML in head

    blixt, your script makes sense, but still does not help my code need.
    I will give you the simplest example. I am making a button that will create a large chunk of html everytime it is clicked. The chunk of html is made up of DIVs, text etc. Some of these divds have ID's and some have classes. The script I am trying to reproduce defines many effects (via mootools). These effects are ID SPECIFIC. So when Someone clicks the button 3 times, I need all 3 chuncks of code to be usable i.e. the script must be reproduced 3 times with the wundow_number being different for all three and the elemnets picking up the effects from the script. All without refreshing the page!

    Its tricky.

  4. #19
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: innerHTML in head

    You want to create a new set of elements every time a button is clicked. Each set of elements should share a number in their ID's. Is this correct?

    The function I posted will work, and here's how you'd use it with the generation code:
    Code:
    <button onclick="newWindow()">New window</button>
    Code:
    var window_number = 1;
    function newWindow() {
        var prefix = "window_" + window_number + "_";
    
        var wone = document.createElement("div");
        wone.id = prefix + "wone";
    
        var botright = document.createElement("div");
        botright.id = prefix + "botright";
    
        var inner = document.createElement("div");
        inner.id = prefix + "inner";
    
        // someElement.appendChild(wone);
        // ...
    
        addScript(window_number);
    
        window_number++;
    }

Page 2 of 2 FirstFirst 12

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured