How to programatically (dynamically) change icon to another?
E.g. to "watch"?
I'm not sure I know what you mean. Could you find an example of doing this with another icon set?
e.g. https://fontawesome.com/how-to-use/svg-with-js
search for "Changing icons by changing class"
<button>Open up <i class="fa fa-angle-right"></i></button>
<script>
document.addEventListener('DOMContentLoaded', function () {
$('button').on('click', function () {
$(this)
.find('[data-fa-i2svg]')
.toggleClass('fa-angle-down')
.toggleClass('fa-angle-right');
});
});
</script>
clicking a icon button changes that icon to another (here, an arrow)
If you have jQuery, this seems to work:
$(".parent svg.feather.feather-circle").replaceWith(feather.icons.square.toSvg());
Essentially - find the existing Feather-generated SVG element and replace it with a new one using the Feather JS function.
@craigrodway's solution should work. If it works for you, feel free to close this issue.
@craigrodway Or without jQuery:
document.querySelector('.parent svg.feather.feather-circle').replaceWith(feather.icons.square.toSvg())
The answer to this question is quite elaborative to explain.
Most helpful comment
If you have jQuery, this seems to work:
$(".parent svg.feather.feather-circle").replaceWith(feather.icons.square.toSvg());Essentially - find the existing Feather-generated SVG element and replace it with a new one using the Feather JS function.