Loading ...
Sorry, an error occurred while loading the content.

DOM manipulation

Expand Messages
  • firmani.maurizio
    How do I add element such or to the DOM using the YUI way? I know how to create a , or a textnode. For instance: var elSpan =
    Message 1 of 4 , Dec 29, 2008
    • 0 Attachment
      How do I add element such <form> or <a> to the DOM using the YUI way?

      I know how to create a <span>, <div> or a textnode. For instance:

      var elSpan = document.createElement("span");
      var elText = document.createTextNode("This is a text node");
      elSpan.appendChild(elText);

      but how do I add an element like:
      <a href="url">link</a>?

      TIA

      Maurizio
    • D. Wayne Fincher
      If you want to go the node manipulation route try this: var anchor = document.createElement( a ); anchor.setAttribute( href , url ); anchor.innerHTML =
      Message 2 of 4 , Dec 29, 2008
      • 0 Attachment
        If you want to go the node manipulation route try this:

        var anchor = document.createElement("a");
        anchor.setAttribute('href', 'url');
        anchor.innerHTML = 'link';

        I'm not sure YUI has a way to do it better than that.

        Now if you want to construct the element as a string and then insert
        using innerHTML, then...

        var anchor = '<a href="url">link</a>';
        YAHOO.util.Dom.get('some_element').innerHTML = anchor;

        Anyways, in my experience, creating and adding elements goes pretty
        smooth in IE, FF, and others.

        Setting styles/classes/and some other things are probably best done
        using methods like:

        Dom.setStyle
        Dom.addClass
        Dom.removeClass
        etcetera


        --- In ydn-javascript@yahoogroups.com, "firmani.maurizio"
        <firmani@...> wrote:
        >
        > How do I add element such <form> or <a> to the DOM using the YUI way?
        >
        > I know how to create a <span>, <div> or a textnode. For instance:
        >
        > var elSpan = document.createElement("span");
        > var elText = document.createTextNode("This is a text node");
        > elSpan.appendChild(elText);
        >
        > but how do I add an element like:
        > <a href="url">link</a>?
        >
        > TIA
        >
        > Maurizio
        >
      • Maurizio Firmani
        Thank you. I missed the innerHTML part. Maurizio ... From: D. Wayne Fincher Date: Monday, December 29, 2008 4:47 pm Subject:
        Message 3 of 4 , Dec 30, 2008
        • 0 Attachment
          Thank you. I missed the innerHTML part.

          Maurizio


          ----- Original Message -----
          From: "D. Wayne Fincher" <slowlychillin@...>
          Date: Monday, December 29, 2008 4:47 pm
          Subject: [ydn-javascript] Re: DOM manipulation
          To: ydn-javascript@yahoogroups.com


          > If you want to go the node manipulation route try this:
          >
          > var anchor = document.createElement("a");
          > anchor.setAttribute('href', 'url');
          > anchor.innerHTML = 'link';
          >
          > I'm not sure YUI has a way to do it better than that.
          >
          > Now if you want to construct the element as a string and then insert
          > using innerHTML, then...
          >
          > var anchor = '';
          > YAHOO.util.Dom.get('some_element').innerHTML = anchor;
          >
          > Anyways, in my experience, creating and adding elements goes pretty
          > smooth in IE, FF, and others.
          >
          > Setting styles/classes/and some other things are probably best done
          > using methods like:
          >
          > Dom.setStyle
          > Dom.addClass
          > Dom.removeClass
          > etcetera
          >
          >
          > --- In ydn-javascript@yahoogroups.com, "firmani.maurizio"
          > <firmani@...> wrote:
          > >
          > > How do I add element such <form> or <a> to the DOM using the YUI way?
          > >
          > > I know how to create a <span>, <div> or a textnode. For instance:
          > >
          > > var elSpan = document.createElement("span");
          > > var elText = document.createTextNode("This is a text node");
          > > elSpan.appendChild(elText);
          > >
          > > but how do I add an element like:
          > > ?
          > >
          > > TIA
          > >
          > > Maurizio
          > >
          >
          >
        • silviadiferente18
          Message 4 of 4 , Dec 30, 2008
          • 0 Attachment
            --- In ydn-javascript@yahoogroups.com, "firmani.maurizio"
            <firmani@...> wrote:
            >
            > How do I add element such <form> or <a> to the DOM using the YUI way?
            >
            > I know how to create a <span>, <div> or a textnode. For instance:
            >
            > var elSpan = document.createElement("span");
            > var elText = document.createTextNode("This is a text node");
            > elSpan.appendChild(elText);
            >
            > but how do I add an element like:
            > <a href="url">link</a>?
            >
            > TIA
            >
            > Maurizio
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.