Skip to content Skip to sidebar Skip to footer

Unable To Access The Dom Which I Passed As A String. How To Do It By Using External Function As I Defined In The Code?

I want to add an event to the 'Important' link i.e. When One user clicks the 'Important' link, the corresponding card color should be changed and saved in the localstorage but, whe

Solution 1:

You were missing index while fetching element inside markNotes:

functionmarkNotes(index) {
   let notes = localStorage.getItem("notes");
   if (notes != null) {
    notesObj = JSON.parse(notes);
   } else {
    notesObj = [];
   }
  let noteCard = document.getElementsByClassName("noteCard")[index];
    noteCard.style.color = "lightblue";
    console.log("Color is applied")
   localStorage.setItem("notes", JSON.stringify(notesObj));
   //showNotes(); you don't need to add this again
}

complete working code fiddle link

Post a Comment for "Unable To Access The Dom Which I Passed As A String. How To Do It By Using External Function As I Defined In The Code?"