title: Vanilla js equivalent of jquery .attr( attributeName, function )
body: <p>I note that jQuery <code>.attr()</code> has a variant which allows you to set an attribute name to a function: see <a href="http://api.jquery.com/attr/#attr-attributeName-function" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I'm trying to find the plain vanilla js equivalent of this, but note that the <code>setAttribute()</code> function only appears to allow you to set an attribute value to a <em>string</em>: see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute" rel="nofollow noreferrer">here</a>.</p>
  
  <p>More specifically, I'm trying to convert a snippet from <a href="https://www.petercarrero.com/examples/stroke/" rel="nofollow noreferrer">this article</a> from jQuery to plain js:</p>
  
  <pre><code>$(function(){
    $('.stroke-double, .stroke-single').attr('title', function(){
      return $(this).html();
    });
  });
  </code></pre>