Interesting challenge to create a simple heart icon that toggles to a filled heart icon. With each press it either calls a function to favorite or unfavorite an item in a news feed. It needs to send in an news item ID so that the correct item gets updated.
My thought was that in my routine I could toggle the ‘hidden’ value of the div to show the empty or full heart icon … but then I realized I might have hundreds of these so how would I know which div to toggle without giving them all unique names (that sounds painful).
In addition I want to call my function to increase or decrease the favorite count. I imagine I could embed a snipped of JS to catch the onclick and make the call. Since this is in a template (componentUrl) I can insure the function gets called with {{this.newsitemID}}
If F7 has an easier way to manage a two state icon and its function calls please fill me in! (especially if its possible to do most of it in HTML without jumping out to the methods on this page)
The function then sets the current element to display:none which works. For some reason accessing the nextSibling returns a #text value but getting the nextSibling.nextSibling returns the second div (hearton) which I then set to display:block … and this fails.
** how do I get the function to format as code in this forum? **
This heart icon is part of a card list in a ComponentUrl file so I imagine I can set the initial value of the heart icon using your example. But this only sets the initial value of the heart icon. When the user clicks on the heart to either favorite or unfavorite a particular card that I need to shift the state of the heart from empty to filled (or the reverse) and set the database boolean.
Its so strange to me that my addFavorite function works for elem.style.display but fails for elem.nextSibling
Is there a reason why elem.nextSibling of heartOff div return a #text item rather than the heartOn div? Is F7 doing something behind the scenes with the DOM?