Favorite Icon

    0

    0

    WiktorrWieSolteq

    The code demonstrates how to add an icon to a list using the class name "favorite-icon". The code then checks to see if the class "in-list" exists, and if it does, it sets the icon's InnerHTML to "<span class='in-list' title='In list'><span class='icon-2' aria-hidden='true'><img src='/Files/Templates/Designs/Swift/Assets/icons/heart.svg'/></span></span>" If the class "not-in-list" exists, the InnerHTML is set to "<span class='in-list' title='In list'><span class='icon-2' aria-hidden='true'><img src='/Files/Templates/Designs/Swift/Assets/icons/heart-filled.

      var favoriteIcon = document.getElementsByClassName("favorite-icon");
    var childClass = favoriteIcon.children[0].classList.value;
    if (childClass = "in-list") {
      favoriteIcon.innerHTML = "<span class='not-in-list' title='Not in list'><span class='icon-2' aria-hidden='true'><img src='/Files/Templates/Designs/Swift/Assets/icons/heart-filled.svg'/></span></span>"
    }
    else if (childClass = "not-in-list"){
      favoriteIcon.innerHTML = "<span class='in-list' title='In list'><span class='icon-2' aria-hidden='true'><img src='/Files/Templates/Designs/Swift/Assets/icons/heart.svg'/></span></span>"
                      }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.