diff -u b/core/misc/ajax.js b/core/misc/ajax.js
--- b/core/misc/ajax.js
+++ b/core/misc/ajax.js
@@ -919,9 +919,11 @@
// If removing content from the wrapper, detach behaviors first.
switch (method) {
// top-level element, and only use the container DIV created above when
- // it doesn't. For more information, please see http://drupal.org/node/736066.
+ // it doesn't. For more information, please see
+ // https://www.drupal.org/node/736066.
if ($new_content.length !== 1 || $new_content.get(0).nodeType !== 1) {
$new_content = $new_content_wrapped;
+ }
// If removing content from the wrapper, detach behaviors first.
@@ -956,7 +958,7 @@
// Attach all JavaScript behaviors to the new content, if it was
// successfully added to the page, this if statement allows
// `#ajax['wrapper']` to be optional.
- if (new_content.parents('html').length > 0) {
+ if ($new_content.parents('html').length > 0) {
// Apply any settings from the returned JSON if available.
settings = response.settings || ajax.settings || drupalSettings;
Drupal.attachBehaviors($new_content.get(0), settings);
@@ -990,10 +992,11 @@
* @param {number} [status]
*/
changed: function (ajax, response, status) {
- if (!$(response.selector).hasClass('ajax-changed')) {
- $(response.selector).addClass('ajax-changed');
+ var $element = $(response.selector);
+ if (!$element.hasClass('ajax-changed')) {
+ $element.addClass('ajax-changed');
if (response.asterisk) {
- $(response.selector).find(response.asterisk).append(' * ');
+ $element.find(response.asterisk).append(' * ');
}
}
},