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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Javascript Node compare

  • 16-05-2009 2: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,263 ✭✭✭✭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,470 ✭✭✭MOH


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


Advertisement