Pages: 1
Print
Author Topic: strElementName  (Read 115 times)
C4
Member

Posts: 10


« on: April 25, 2017, 07:10:43 PM »

Hi,

We are using XMetal Author Essential 11.

I'm trying to write a macro to find an element using:

// XMetaL Script Language JSCRIPT:
var rng=ActiveDocument.Range;
rng.MoveToElement("P",false);
// make the range visible
rng.Select();

Is there any way to move to the end of the element rather than the beginning of the element?

Thanks.
Logged
tonys
JustSystems Partner
Member

Posts: 74


« Reply #1 on: April 26, 2017, 03:34:05 PM »

To move the cursor before the end tag:

rng.MoveToElement("P");
rng.SelectContainerContents();
rng.Collapse(0);

To move after the end tag:

rng.MoveToElement("P");
rng.SelectAfterContainer();
Logged
C4
Member

Posts: 10


« Reply #2 on: April 26, 2017, 05:55:44 PM »

Thanks

I tried both of those and it took me to the beginning of the element.

I've changed my code to this and it seems to work.

var rng=ActiveDocument.Range;
rng.MoveToElement("P",true);
rng.Select();
Selection.SelectAfterNode(Selection.ContainerNode);
Logged
tonys
JustSystems Partner
Member

Posts: 74


« Reply #3 on: April 26, 2017, 06:06:15 PM »

Maybe because you didn't call rng.Select()?

For efficiency, you should do everything with the Range object, then call the Select() method at the end.
Logged
Pages: 1
Print
Jump to:  

email us