Using regular expressions to find img tags without an alt attribute

前端 未结 8 1775
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 11:37

I am going through a large website (1600+ pages) to make it pass Priority 1 W3C WAI. As a result, things like image tags need to have alt attributes.

What would be the

8条回答
  •  佛祖请我去吃肉
    2021-01-30 11:55

    I wrote a simple code for this without Regex

    let arr = []
    $('img')
    .filter(function() {
      arr.push(this.alt)
    })
    document.write(arr.filter(a=>!a).length + ' img without alt tag')
    

提交回复
热议问题