简体   繁体   English

在Tritium中,如何切换两个元素的位置?

[英]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? 切换两个子元素顺序的最快方法是什么?

You can use the move_to function with the position specifier after like so: 您可以使用move_to与位置确定功能after ,像这样:

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 这是氚运动场的链接: http//play.tritium.io/4078eded016a450e165d9f358cd547d3e47602d6

I like to use move_to with bottom. 我喜欢用move_to底部。 This is good also if there is no id on the elements, so you can just select the first, for instance and then move it to the bottom. 如果元素上没有id,这也很好,所以你可以选择第一个,例如然后将它移到底部。 It's another variation from @noj response: 这是@noj响应的另一个变种:

$("//div[@id='parentDiv')]/div[@id='anyChildGoingToBottom'") {
  move_to("..", "bottom")
}

http://tester.tritium.io/923b23858ddb8fd7d9ccf348b2e7dc67fddb8cde http://tester.tritium.io/923b23858ddb8fd7d9ccf348b2e7dc67fddb8cde

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM