diff --git a/inst/htmlwidgets/jstreer.js b/inst/htmlwidgets/jstreer.js
index 06f8c5d..9571182 100644
--- a/inst/htmlwidgets/jstreer.js
+++ b/inst/htmlwidgets/jstreer.js
@@ -247,7 +247,7 @@ HTMLWidgets.widget({
if(x.search) {
if(x.grid) {
var $div = $(gridSearchBoxes(x.grid, el.id));
- var $midWrapper = $(".jstree-grid-midwrapper");
+ var $midWrapper = $el.closest(".jstree-grid-midwrapper");
$div.insertBefore($midWrapper);
var divSelector = "#" + el.id + "-searchFields";
//add search functionality to the input fields