diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js
index a9fc1143c..6f1195910 100644
--- a/tests/unit/autocomplete/autocomplete_core.js
+++ b/tests/unit/autocomplete/autocomplete_core.js
@@ -188,4 +188,14 @@ test( "ARIA", function() {
"Live region for multiple values" );
});
+test( ".replaceWith() (#9172)", function() {
+ expect( 1 );
+
+ var element = $( "#autocomplete" ).autocomplete(),
+ replacement = "
test
",
+ parent = element.parent();
+ element.replaceWith( replacement );
+ equal( parent.html(), replacement );
+});
+
}( jQuery ) );
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index 3d0343379..28cfdf2fb 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -296,7 +296,7 @@ $.widget( "ui.autocomplete", {
"aria-live": "polite"
})
.addClass( "ui-helper-hidden-accessible" )
- .insertAfter( this.element );
+ .insertBefore( this.element );
// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete