質問するログイン新規登録

回答編集履歴

1

altにセットするために<br>を除去していましたが、<br>に限らずhtmlタグを削除できるよう変更しました。

2016/09/21 08:01

投稿

PenelopeG
PenelopeG

スコア31

answer CHANGED
@@ -14,9 +14,9 @@
14
14
  $('.rwd_txt2').each(function(i){
15
15
  var imgpath = $(this).attr('data-imgpath');
16
16
  var imgalt = $(this).text();
17
- imgalt = imgalt.replace(/<br>/g, "");
17
+ imgalt = imgalt.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, "");
18
18
  $(this).text("");
19
19
  $(this).append('<img src="' + imgpath + '" alt="' + imgalt + '">');
20
20
  });
21
21
  }
22
- ```
22
+ ```