diff --git a/modules/media_wysiwyg/js/media_wysiwyg.filter.js b/modules/media_wysiwyg/js/media_wysiwyg.filter.js
old mode 100644
new mode 100755
index 4a0ac0d..ee1efcf
--- a/modules/media_wysiwyg/js/media_wysiwyg.filter.js
+++ b/modules/media_wysiwyg/js/media_wysiwyg.filter.js
@@ -55,6 +55,11 @@
       // Convert all xhtml markup to html for reliable matching/replacing.
       content = content.replace(/[\s]\/\>/g, '>');
 
+      // "Normalize" the content html - when html is processed by jQuery, attributes can end up in a different order.
+      // This causes issues with our search and replace, so we normalize here before iterating through our media
+      // elements and risk getting them mixed up.
+      content = $('<div>').append(content).html();
+
       // Re-build the macros in case any element has changed in the editor.
       $('.media-element', content).each(function(i, element) {
         var markup = Drupal.media.filter.outerHTML($(element));
