search

Home  >  Q&A  >  body text

javascript - Can I use calc() when setting attributes with setAttribute?

Can I use calc() when setting attributes with setAttribute?

<svg id='svg' xmlns="http://www.w3.org/2000/svg" width="1122" height="800"></svg>
<script>
    document.getElementById('svg').setAttribute('height','calc(100vw * 0.5)')
</script>

This is set as a string.

PHP中文网PHP中文网2753 days ago581

reply all(1)I'll reply

  • 某草草

    某草草2017-05-19 10:39:19

    To set the style, you can pass:

    document.getElementById('svg').style.height = 'calc(100vw * 0.5)';

    reply
    0
  • Cancelreply