View Full Version : get parent element of control property

05-09-2004, 03:41 PM
I already have the code to get the parent element of basic text inside an iFrame, but the code doesnt work when you select a control element, for example an image or input text box.

here's the code I have which gets the parent element and builds an HTML path of the cursor element.

var cursor = iView.document.selection.createRange();
var element = cursor.parentElement();

while (element.nodeName.toUpperCase() != "HTML") {
//go through the elements and build the path
path += "<" + element.nodeName + ">";
if (element.parentNode) {
element = element.parentNode;

The error message I get in JS is

"object doesnt support this property or method"

any help is much appreciated.
thanks :D

05-10-2004, 04:10 AM
When selection.type == "Control", a controlRange (http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/controlrange.asp) collection is returned -- which does not have a parentElement() method.

- in that case it would be something like cursor(0).parentElement;

05-10-2004, 12:44 PM
cheers! that worked! :D :thumbsup: