Quantcast
Viewing all articles
Browse latest Browse all 88

Strike through a div on click

I am fairly new at JavaScript and am creating a simple To Do list app, however, I am having trouble creating a JS function that crosses out the text/task of a particular div onClick.

Below is the code on what I have so far. I have attempted to use the strike() function in the crossOut() function in JS based on what I read online, however, it was unsuccessful.

function displayText() {  let input = document.getElementById("textBar");  let toDoContainer = document.getElementById("text");  toDoContainer.innerHTML += "<div class='toDo' onclick='crossOut()'>"+ input.value +"</div>";  toDoContainer.innerHTML += "<br><br><br><br>";  input.value = "";}function crossOut() {  let toDoContainer = document.getElementById("text");  toDoContainer.strike();}
.toDo {  cursor: pointer;}
<div id="container"><div id="today">Today is:</div><br><div id="date"></div><input type="text" placeholder="Enter task" id="textBar"><button type="submit" id="submit" onclick="displayText()">Add</button><div id="text"><!--<div class="toDo" onclick="crossOut()">Design Text</div>--></div></div>

Viewing all articles
Browse latest Browse all 88

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>