diff --git a/core/js/js.js b/core/js/js.js index e8c51a37b60..ba8e1597023 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -2666,10 +2666,19 @@ $.fn.position = function( options ) { var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions, - // Make sure string options are treated as CSS selectors - target = typeof options.of === "string" ? - $( document ).find( options.of ) : - $( options.of ), + // Make sure string options are treated as CSS selectors and avoid HTML parsing + target = ( function( of ) { + if ( typeof of === "string" ) { + return $( document ).find( of ); + } + if ( of && of.target ) { + return $( of.target ); + } + if ( of && ( of.jquery || of.nodeType || of === window || of === document ) ) { + return $( of ); + } + return $(); + } )( options.of ), within = $.position.getWithinInfo( options.within ), scrollInfo = $.position.getScrollInfo( within ),