SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help! creating button getElementByClassName

    Hi:

    Trying to to create and style a (print) button ...

    I have a span class, that I want to be an object that is called: do I need getElementByID?

    I am stuck with this - Can anyone help? > thanks.gg (Aside: yes, I am using YUI DOM)

    if (window.print) {

    // NEW CODE for the new button
    function loader(){
    //put everything in here
    //MAIN
    YAHOO.util.Event.addListener(window, "load", loader);

    //create HTML string that is the button
    var oElement = document.getElementById("print_button_node");
    //Return an array of HTMLElements with the given class.
    Array getElementsByClassName ("print_button_node")
    // use 1) DOM, or 2)innerHTML to dynamically write button in any
    "print_button_node" class (could be more than one)
    var elements =
    YAHOO.util.Dom.getElementsByClassName("print_button_node", 'span');
    //retreive element collection, in a loop...
    //decorate with button



    //Print function
    function printpage()
    {
    window.print()
    }

    }//END loader

    }

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a simple script: Help please!

    OK, I'm going to start over, here.

    I want to write a JavaScript that creates a button with a print event attached.

    I want the script to get the class name "dynPrintButton" and then return the array "dynPrintButton" - How do I use innerHTML to dynamically write the button in any "dynPrintButton" class?

    This is what I have so far in script, but I'm not sure if my script is straying me from my goal:
    //create HTML string that is the button
    var oElement = document.getElementByClassName("dynPrintButton");
    //Return an array of HTMLElements with the given class.
    Array getElementsByClassName ("dynPrintButton");
    // use innerHTML to dynamically write button in any "print_button_node" class (could be more than one)
    document.getElementByClassName("dynPrintButton").innerHTML;


    for my HTML: don't know if I need this:
    <span>
    <input type="button" value="Print Page" class="dynPrintButton" onclick="printpage()" />
    </span>

    or this:
    <span class="dynPrintButton"></span>


    PS: also confused about single and double quotes .. please help, and thanks, gg

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    these are the errors I'm getting:

    missing ; before statement
    [Break on this error] var Array getElementsByClassName ('dynPrintButton');\n
    test_js.js (line 15)
    [Exception... "'Component does not have requested interface' when calling method: [nsIInterfaceRequestor::getInterface]" nsresult: "0x80004002 (NS_NOINTERFACE)" location: "<unknown>" data: no]
    [Break on this error] undefined
    [Exception... "'Component does not have requested interface' when calling method: [nsIInterfaceRequestor::getInterface]" nsresult: "0x80004002 (NS_NOINTERFACE)" location: "<unknown>" data: no]

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var Array = getElementsByClassName

    not

    var Array getElementsByClassName

    also, what are you actually doing with this line?

    document.getElementByClassName("dynPrintButton").innerHTML;



Bookmarks

Posting Permissions

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