Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript Node compare

Options
  • 16-05-2009 3:22pm
    #1
    Registered Users Posts: 590 ✭✭✭


    Hi,

    I can't seem to find a Javascript method to compare two DOM nodes to check if they're equal. This surprises me as I would have suspected this would be a commonly needed function.

    i.e. these two nodes would be equal
    <rootNode>
      <childOne type='some type'>
        value1
      </childOne>
      <childTwo type='another type' type='yet another'/>
    </rootNode>
    
    <rootNode>
      <childTwo type='yet another' type='another type'/>
      <childOne type='some type'>
        value1
      </childOne>
    </rootNode>
    

    i.e. order of children, attributes, etc. doesn't matter.

    Anyone know if there's a standard cross browser function to do this?

    Any help appreciated.


Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Can you not use the xpath to find the node by name rather than by index?


  • Registered Users Posts: 590 ✭✭✭bman


    I'm not sure I understand your reply. I'm not trying to find the node by name or index, simply check if two nodes are equal, regardless of attribute or element order.


  • Registered Users Posts: 6,465 ✭✭✭MOH


    Not a method, but there's some code to do it here


Advertisement