diff --git a/src/js/_enqueues/admin/tags-suggest.js b/src/js/_enqueues/admin/tags-suggest.js
index 7a19002a4c..0381f0053c 100644
--- a/src/js/_enqueues/admin/tags-suggest.js
+++ b/src/js/_enqueues/admin/tags-suggest.js
@@ -40,7 +40,7 @@
// Do not initialize if the element doesn't exist.
if ( ! $element.length ) {
- return;
+ return this;
}
options = options || {};
@@ -156,14 +156,16 @@
$element.autocomplete( options );
// Ensure the autocomplete instance exists.
- if ( $element.autocomplete( 'instance' ) ) {
- $element.autocomplete( 'instance' )._renderItem = function( ul, item ) {
- return $( '
' )
- .text( item.name )
- .appendTo( ul );
- };
+ if ( ! $element.autocomplete( 'instance' ) ) {
+ return this;
}
+ $element.autocomplete( 'instance' )._renderItem = function( ul, item ) {
+ return $( '' )
+ .text( item.name )
+ .appendTo( ul );
+ };
+
$element.attr( {
'role': 'combobox',
'aria-autocomplete': 'list',
@@ -178,9 +180,10 @@
if ( inputValue ) {
$element.autocomplete( 'search' );
}
- } )
+ } );
+
// Returns a jQuery object containing the menu element.
- .autocomplete( 'widget' )
+ $element.autocomplete( 'widget' )
.addClass( 'wp-tags-autocomplete' )
.attr( 'role', 'listbox' )
.removeAttr( 'tabindex' ) // Remove the `tabindex=0` attribute added by jQuery UI.