cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to: Swap two child nodes of element by using Styler APP

JuhaA
1-Newbie

How to: Swap two child nodes of element by using Styler APP

I have two div elements in section element. I would like to change order of those two div elements depending is element in even or odd pages. When I run PDF publish I don't get any errors. Any ideas or workarounds how to do this?

var currentNode = formatting.currentXMLNode;

if (formatting.currentPage.pageNumber % 2 == 0) {

//note! first element in section is title

  if (currentNode.childNodes[2]!=null && currentNode.childNodes[1] != null){

    currentNode.insertBefore(currentNode.childNodes[2],currentNode.childNodes[1]);

    formatting.write(currentNode.nodeName + " Child node1:" + currentNode.childNodes[1].nodeName + " Child node2:" + currentNode.childNodes[2].nodeName);

  }

}

1 ACCEPTED SOLUTION

Accepted Solutions
JuhaA
1-Newbie
(To:JuhaA)

My mistake


var currentNode = formatting.currentXMLNode;

if (formatting.currentPage.pageNumber % 2 == 0) {

  if (currentNode.childNodes[2]!=null && currentNode.childNodes[1] != null){

    var firstDiv=currentNode.childNodes[1];

    var seconDiv=firstDiv.augNextSibling;

    firstDiv.insertBefore(seconDiv,firstDiv);

  }

  else

    formatting.write("Both are nulls_");

}

View solution in original post

1 REPLY 1
JuhaA
1-Newbie
(To:JuhaA)

My mistake


var currentNode = formatting.currentXMLNode;

if (formatting.currentPage.pageNumber % 2 == 0) {

  if (currentNode.childNodes[2]!=null && currentNode.childNodes[1] != null){

    var firstDiv=currentNode.childNodes[1];

    var seconDiv=firstDiv.augNextSibling;

    firstDiv.insertBefore(seconDiv,firstDiv);

  }

  else

    formatting.write("Both are nulls_");

}

Top Tags