<p>How can I go through all external links in a div with javascript, adding (or appending) a class and alt-text?</p>

<p>I guess I need to fetch all objects inside the div element, then check if each object is a , and check if the href attributen starts with http(s):// (should then be an external link), then add content to the alt and class attribute (if they don't exist create them, if they do exists; append the wanted values).</p>

<p>But, how do I do this in code?</p>

This can be accomplished pretty easily with
Jquery
. You would add this to the onload:
```
```
$("div a[href^='http']").each(function() {
  $(this).attr("alt",altText);
  var oldClassAttributeValue = $(this).attr("class");
  if(!oldClassAttributeValue) {
   $(this).attr("class",newClassAttributeValue);
  }
});
```
```
You could modify this to add text. Class can also be modified using the
css
function.