Home Forums General XMetaL Discussion Deleting an element Reply To: Deleting an element

mag3737

Reply to: Deleting an element

Ok, I think the answer is that before you do the RemoveContainerTags() you need to verify that after doing MoveToElement() your range/selection is actually located inside the element whose tags you want to remove. Otherwise, if it so happens that the tags of the resulting location can also be validly removed, they will be.

Try this:

[code]
var rng=ActiveDocument.Range;
rng.MoveToElement(“autovalue”, true);
rng.Select();
if ((Selection.CanRemoveContainerTags) && (Selection.ContainerName == “autovalue”)) {
Selection.RemoveContainerTags();
}
[/code]

As a side note, you might consider doing the rng.Select() after the tags are removed, instead of before. This should work just as well, with the bonus(?) effect that the cursor will not move unless some tags actually do get removed (i.e. if the code performs a no-op, the user's cursor will remain where it was):

[code]
var rng=ActiveDocument.Range;
rng.MoveToElement(“autovalue”, true);
if ((rng.CanRemoveContainerTags) && (rng.ContainerName == “autovalue”)) {
rng.RemoveContainerTags();
rng.Select();
}
[/code]

Reply

Products
Downloads
Support