jointjs
Version:
JavaScript diagramming library
12 lines (8 loc) • 1.18 kB
HTML
<pre class="docs-method-signature"><code>util.setAttributesBySelector(el, attrs)</code></pre>
<p>Set attributes on the DOM element (SVG or HTML) <code>el</code> and its descendants based on the selector in the <code>attrs</code> object. The <code>attrs</code> object is of the form: <code>{ [selector]: [attributes }</code>. For example:</p>
<pre><code>var myEl = document.querySelector('.mydiv');
joint.util.setAttributesBySelector(myEl, {
'.myDiv': { 'data-foo': 'bar' }, // Note the reference to the myEl element itself.
'input': { 'value': 'my value' }
});</code></pre>
<p>The code above sets <code>'data-foo'</code> attribute of the <code>myEl</code> element to the value <code>'bar'</code> and <code>'value'</code> attribute of all the descendant inputs to the value <code>'my value'</code>. This is a convenient way of setting attributes on elements (including themselves) and their descendants. Note that <code>'class'</code> attribute is treated as a special case and its value does not override the previous value of the <code>'class'</code> attribute. Instead, it adds this new class to the list of classes for the element referenced in the selector.</p>