Index: src/wp-includes/class-wp-admin-bar.php
===================================================================
--- src/wp-includes/class-wp-admin-bar.php	(revision 46605)
+++ src/wp-includes/class-wp-admin-bar.php	(working copy)
@@ -540,16 +540,19 @@
 		if ( $has_link ) {
 			$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
 			echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'";
-			if ( ! empty( $node->meta['onclick'] ) ) {
-				echo ' onclick="' . esc_js( $node->meta['onclick'] ) . '"';
-			}
 		} else {
 			$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
 			echo '<div class="ab-item ab-empty-item"' . $aria_attributes;
 		}
 
 		foreach ( $attributes as $attribute ) {
-			if ( ! empty( $node->meta[ $attribute ] ) ) {
+			if ( empty( $node->meta[ $attribute ] ) ) {
+				continue;
+			}
+
+			if ( 'onclick' === $attribute ) {
+				echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'";
+			} else {
 				echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'";
 			}
 		}
