I have the following problem.
I have a tree view control in .NET and I have created a autocomplete search box to search the tree for a name – which then I can select and it highlights the item with a selected class.
The tree view is pretty long so I have given it a height and overflow scroll.
The problem is that I want view or scroll down to the selected item when I’ve searched for it.
So i have created the following script to scrollIntoView it but this doesn’t seem to work:
function search_itemSelected(sender, e) {
var hdSearchID = $get('<%= hdSearchID.ClientID %>');
hdSearchID.value = e.get_value();
var selectedElement = $("div.node.cen.selected"); // This works
if (selectedElement != null) {
selectedElement[0].scrollIntoView = 10; // This keeps coming back as undefined
}
}
First: change
to
because
$("div.node.cen.selected");will never returnnull. jQuery always returns a jQuery object (empty or not, but a jQuery object)So in the case where it is empty, the
selectedElement[0]will return undefined and thus thescrollIntoViewdoes not exist..Second:
scrollIntoViewis a function and so you do not assign a value to it. You need to call it with