For image find attr "title" and replace with "alt"
I am trying to replace the "title"(not assigned) of each image with the assigned alternative text.
For example:
Before:
<img src="imagesYolloSwag.jpg" alt="swag" width="136" height="143" > // title not defined
After:
<img src="imagesYolloSwag.jpg" alt="swag" width="136" height="143" >
// title added, and value picked from alt text
What am i doing wrong here? Please help.
<script>
$(document).ready(function() {
$('img').each(function() {
var altX = $(this).attr('alt');
$(this).attr('title').replaceWith(altX);
});
});
</script>