Search code examples
moovwebtritium

In Tritium, how do I switch the position of two elements?


I have two elements next to each other like this:

<div id="parent">
    <div id="child1"></div>
    <div id="child2"></div>
</div>

What's the fastest way to switch the order of the two child elements?


Solution

  • You can use the move_to function with the position specifier after like so:

    html() {
      $("/html/body") {
        $("./div[@id='parent']/div[@id='child1']") {
            move_to("../div[@id='child2']", "after") 
        }
      }
    }
    

    Here's a link to tritium playground: http://play.tritium.io/4078eded016a450e165d9f358cd547d3e47602d6