I have a simple question about inline SVG icons and how to handle them in HTML, CSS, and jQuery. Despite reading numerous resources, I still struggle with implementing the functionality where clicking on one icon changes it to another.
My objective: To toggle between two different icons (e.g., + icon to - icon) when clicked.
What I've done so far: I downloaded two SVG icons from Noun Project and added the code for the + icon in my HTML markup. Here's a glimpse of where I'm at currently.
<div class="border"></div>
<div class="clickableList">
<span class="types">Swap icons</span>
<svg width="20px" height="20px" viewBox="0 0 74 74" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>noun_1776266_cc</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="noun_1776266_cc_2" transform="translate(0.000000, -1.000000)" fill="#000000" fill-rule="nonzero">
<g id="Group" transform="translate(0.000000, 0.637820)">
<polygon id="Shape" points="33 0.36218 33 33.36218 0 33.36218 0 41.3622 33 41.3622 33 74.3622 41 74.3622 41 41.3622 74 41.3622 74 33.36218 41 33.36218 41 0.36218 33 0.36218"></polygon>
</g>
</g>
</g>
</svg>
</div>
.types {
font-size: 20px;
font-family: arial;
}
$('.clickableList').click(function() {
event.preventDefault();
I'm now struggling with integrating the second icon into my HTML so that when the first icon is clicked, it morphs into this new icon. Below is the markup for the second icon that's causing me some confusion.
<!-- second SVG-->
<svg width="20px" height="20px" viewBox="0 0 74 74" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>noun_line_1776294</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="noun_line_1776294" transform="translate(-6.000000, -31.000000)">
<g id="Group" transform="translate(0.000000, 0.637820)">
<polygon id="Shape" fill="#000000" fill-rule="nonzero" points="6 30.36218 6 38.36218 68 38.36218 68 30.36218"></polygon>
<rect id="Rectangle" x="0" y="0" width="74" height="69"></rect>
</g>
</g>
</g>
</svg>