From eabda590c88185a75cb7ec621a0d210d2cf1418a Mon Sep 17 00:00:00 2001 From: Jay Dansand Date: Wed, 14 Feb 2018 08:27:29 -0600 Subject: [PATCH] Prevent setting alt=String("undefined") when the original IMG has no alt. --- src/js/image.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/image.js b/src/js/image.js index f5687c85..fc389c6e 100644 --- a/src/js/image.js +++ b/src/js/image.js @@ -190,7 +190,11 @@ $.magnificPopup.registerModule('image', { var img = document.createElement('img'); img.className = 'mfp-img'; if(item.el && item.el.find('img').length) { - img.alt = item.el.find('img').attr('alt'); + // Sometimes the img does not have an alt attribute. jQuery 1.6+ will + // then return /undefined/, setting img.alt=String("undefined"). + if(item.el.find('img').attr('alt')) { + img.alt = item.el.find('img').attr('alt'); + } } item.img = $(img).on('load.mfploader', onLoadComplete).on('error.mfploader', onLoadError); img.src = item.src;