turning a string to the dom object it represents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yovalk
    New Member
    • Apr 2007
    • 15

    turning a string to the dom object it represents

    I have a string which represents a dom object.
    How do I turn it into an object like document,
    which I can traverse and use methods like
    getElementByTag Name()?

    Thanks alot,
    Yuval
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    window["document"].someMethod().

    Comment

    • yovalk
      New Member
      • Apr 2007
      • 15

      #3
      What do you mean?
      I have a string which is html code, how do I turn it into a document?
      Thanks,
      Yuval

      Comment

      • traineeirishprogrammer
        New Member
        • Jul 2007
        • 24

        #4
        See with javascript a keyed array is equivilant to an object property
        i.e
        Code:
          array["name"] === array.name
        So when traversing the dom you can for example input a string

        "document"

        which you could use as

        i.e
        Code:
        window["document"].firstChild
        same as

        Code:
        window.document.firstChild

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Yes, that's correct. Objects are also associative arrays in JavaScript.

          If you still can't get it to work, post your code or an example string.

          Comment

          Working...