I have an issue with the replaced HTML elements.
I am using jquery on bookmark svg icon to replace it with filled/unfilled bookmark on some div elements.
The code below works well on html elements that are already in my html file however the click event does not fire on the replaced SVG element.
bookmark_Unfilled = ' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="blue" class="bi bi-bookmark" viewBox="0 0 16 16"> <path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.777.416L8 13.101l-5.223 2.815A.5.5 0 0 1 2 15.5V2zm2-1a1 1 0 0 0-1 1v12.566l4.723-2.482a.5.5 0 0 1 .554 0L13 14.566V2a1 1 0 0 0-1-1H4z"/></svg> ';
bookmark_Filled = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="blue" class="bi bi-bookmark-fill" viewBox="0 0 16 16"> <path d="M2 2v13.5a.5.5 0 0 0 .74.439L8 13.069l5.26 2.87A.5.5 0 0 0 14 15.5V2a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2z"/> </svg>' ;
$( " .bi-bookmark" ).click(function() {
// console.log($(this));
// console.log($(this)[0]['classList'][1]);
$(this).replaceWith(bookmark_Filled);
});
$( ".bi-bookmark-fill" ).click(function() {
$(this).replaceWith(bookmark_Unfilled);
});
I might missing something could you please help me out. THere are several bookmarks in my html file I always want to change the value of the bookmark that was clicked.