find image tags with alt attribute without double quotes and replace with empty double quotes
<img src="first.jpg" alt="first" width="500" height="600" />
<img src="second.jpg" alt width="500" height="600" />
<img src="third.jpg" alt="third" width="500" height="600" />
<img src="fourth.jpg" alt width="500" height="600" />
<img src="fifth.jpg" alt="" width="500" height="600" />
find image tags with alt attribute without double quotes and replace with empty double quotes for ADA accessibility, I need to jquery to find second and fourth img tags replace with alt="" just like fifth. This is sample html markup, a page can have this instances 10 or 20 instances, all these should be replaced with alt=""
I tried this below didn't work
$(function() {
$("img").each(function() {
if (this.alt) {
console.log(this.alt);
} else {
$(this).attr('alt', "");
}
});
});