Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript Node compare

  • 16-05-2009 03:22PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


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


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,475 ✭✭✭MOH


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


Advertisement