Skip to main content
1-Visitor
April 29, 2016
Solved

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

  • April 29, 2016
  • 1 reply
  • 1074 views

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);

  }

}

Best answer by 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_");

}

1 reply

JuhaA1-VisitorAuthorAnswer
1-Visitor
April 29, 2016

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_");

}