Incorrect rendering of the <li> tag

I've been working on creating a simple web "to do list" but I've encountered an issue. When I manually add todos and click on them, the 'text-decoration: line-through;' property is ignored, and I can't see the strikethrough effect on my todo items.

Upon comparing the differences between the applied .lineThrough class to two li elements, it seems that the manually added li elements are automatically being assigned the following classes:

.far {  
li:nth-child(2n) {  
   font-family: 'Font Awesome 5 Free';  
   font-weight: 400;    
}   
.fa, .fas, .far, .fal, .fad, .fab { 
   -moz-osx-font-smoothing: grayscale;  
   -webkit-font-smoothing: antialiased;
   display: inline-block;   
   font-style: normal;  
   font-variant: normal;    
   text-rendering: auto;    
   line-height: 1;

}
user agent stylesheet   
i { 
   font-style: italic;  
   background: white;
}

What could possibly be causing this problem?

This is an excerpt from my .js file:

$("i").on("click",function (){  
    $(this).parent().fadeOut(500,function () {
        $(this).remove();
    });
}) 


$("ul").on("click","li",function (){
    $(this).toggleClass("lineThrough");    
}) 

$("#plusBtn").on("click",function(){
    var newTodo = $("#searchBox").val();
    var newTodo = "<li> <i class='far fa-trash-alt'> </i>"+newTodo+"</li>"
    if($("#searchBox").val() != ""){
        $("#toDos").append(newTodo);
        $("#searchBox").val("");
    }
})


$("#searchBox").on("keypress",function(k){ 
    if(k.which == 13){
        var newTodo = $("#searchBox").val();
        var newTodo = "<li><i class='far fa-trash-alt'>"+newTodo+"</i></li>"
        if($("#searchBox").val() != ""){
            $("#toDos").append(newTodo);
            $(this).val("");
        }
    }
})
My .css file
body{
    background-image:linear-gradient(to right, #076585 ,#fff); ;

} 

#table{

    width: 350px;  
    margin: 0 auto;
    margin-top: 100px;
    box-shadow: 10px 10px 20px   #79777767;

}
#todoTitle{
    background: rgb(88, 88, 214);
    height: 45px;
    line-height: 50px;
    padding-left: 10px;
    color: whitesmoke;
    font-size: 25px;

}

#plusBtn{
    background: transparent;
    border: 0;
    color: white;
    font-weight: bold;
    font-size: 45px;
    float: right;
    line-height: 45px;
    outline: none;
}

#searchBox{
    width: 100%;
    border: 0;
    padding: 0;
    height: 45px;
    font-size: 20px;
    padding-left: 10px;
    color: gray;
    box-sizing: border-box;
}
#toDos{
    list-style-type: none;
    padding: 0;
    margin: 0;

}

li{
    padding: 0;
    width: 100%;
    background: rgb(240, 240, 240);
    padding-left: 10px;
    box-sizing: border-box;
    height: 45px;
    line-height: 45px;
    font-size: 25px;
    color: gray;

}

li:nth-child(2n){
    background: white;

}

.lineThrough{
    text-decoration: line-through;
    color: rgb(182, 179, 179);

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>TO DO LIST</title>
    <link rel="stylesheet" type="text/css" href="tdl_css.css">
    <script type = "text/javascript" src="jquery-3.4.1.min.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Gupter&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300i&display=swap" rel="stylesheet">
    <link rel = "stylesheet" type ="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
</head>
<body>

    <div id = "table">
       <div id = "todoTitle">TO-DO LIST
            <button id= "plusBtn">+</button>
       </div>
       <input type="text" id = "searchBox" placeholder="Add New Todo"></input>

       <ul id="toDos">
        <li> <i class="far fa-trash-alt"></i>safsdfsdf</li>
        <li> <i class="far fa-trash-alt"></i>sasdddsdfsdfsdf</li>
       </ul>


    </div>




    <script type = "text/javascript" src="tdl_js.js"></script>
</body>
</html>

Answer №1

The problem arises from the new value being inserted within an <i> tag instead of a <li> tag like this:

<li><i class='far fa-trash-alt'>Value</i></li>
instead of
<li><i class='far fa-trash-alt'></i>value</li>
.

Make sure to insert the value at the appropriate location for it to function correctly. It seems like an unintentional error because you handled it correctly for #plusBtn but missed it for #searchBox.

I have made the necessary corrections for you. Please confirm

$("i").on("click",function (){  
    $(this).parent().fadeOut(500,function () {
        $(this).remove();
    });
})


$("ul").on("click","li",function (){
    $(this).toggleClass("lineThrough");    
})


$("#plusBtn").on("click",function(){
    var newTodo = $("#searchBox").val();
    var newTodo = "<li> <i class='far fa-trash-alt'> </i>"+newTodo+"</li>"
    if($("#searchBox").val() != ""){
        $("#toDos").append(newTodo);
        $("#searchBox").val("");
    }
})


$("#searchBox").on("keypress",function(k){ 
    if(k.which == 13){
        var newTodo = $("#searchBox").val();
        var newTodo = "<li><i class='far fa-trash-alt'></i>"+newTodo+"</li>" //Check here fixed
        if($("#searchBox").val() != ""){
            $("#toDos").append(newTodo);
            $(this).val("");
        }
    }
})
body{
    background-image:linear-gradient(to right, #076585 ,#fff); ;

}

#table{

    width: 350px;  
    margin: 0 auto;
    margin-top: 100px;
    box-shadow: 10px 10px 20px   #79777767;

}
#todoTitle{
    background: rgb(88, 88, 214);
    height: 45px;
    line-height: 50px;
    padding-left: 10px;
    color: whitesmoke;
    font-size: 25px;

}

#plusBtn{
    background: transparent;
    border: 0;
    color: white;
    font-weight: bold;
    font-size: 45px;
    float: right;
    line-height: 45px;
    outline: none;
}

#searchBox{
    width: 100%;
    border: 0;
    padding: 0;
    height: 45px;
    font-size: 20px;
    padding-left: 10px;
    color: gray;
    box-sizing: border-box;
}
#toDos{
    list-style-type: none;
    padding: 0;
    margin: 0;
    
    
}

li{
    padding: 0;
    width: 100%;
    background: rgb(240, 240, 240);
    padding-left: 10px;
    box-sizing: border-box;
    height: 45px;
    line-height: 45px;
    font-size: 25px;
    color: gray;
    
}

li:nth-child(2n){
    background: white;

}

.lineThrough{
    text-decoration: line-through;
    color: rgb(182, 179, 179);
   
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>TO DO LIST</title>
    <link rel="stylesheet" type="text/css" href="tdl_css.css">
    <script type = "text/javascript" src="jquery-3.4.1.min.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Gupter&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300i&display=swap" rel="stylesheet">
    <link rel = "stylesheet" type ="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
</head>
<body>
    
    <div id = "table">
       <div id = "todoTitle">TO-DO LIST
            <button id= "plusBtn">+</button>
       </div>
       <input type="text" id = "searchBox" placeholder="Add New Todo"></input>
        
       <ul id="toDos">
        <li> <i class="far fa-trash-alt"></i>safsdfsdf</li>
        <li> <i class="far fa-trash-alt"></i>sasdddsdfsdfsdf</li>
       </ul>


    </div>


    <script type = "text/javascript" src="tdl_js.js"></script>
</body>
</html>

Trust this explanation helps. Feel free to reach out for any further assistance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Operate on Nested JSON Arrays

I have the following JSON array: var salesData = [ { "products": "Cars", "solddate" : "2022-01-01", "noofitems" : " ...

Accessing Data from the Wikipedia API

After receiving a JSON response with the following structure: { "batchcomplete": "", "query": { "pages": { "97646": { "pageid": 97646, "ns": 0, "title": "Die Hard", "extract": "Die Hard is a 1988 ...

When render returns another component, React does not invoke componentWillMount

Here is my code setup: const Dashboard = React.createClass({ getInitialState(){ return { user: JSON.parse(localStorage.getItem('user')) }; }, componentWillMount(){ var self = this; $.get({ url: 'http://127 ...

Looking for a comprehensive pagination solution using jQuery and Ajax?

Hello, I've been struggling to implement pagination along with displaying data in my project. I have managed to display the data successfully, but incorporating pagination has proven to be a challenge for me. Does anyone have any examples or hints on ...

Display a message indicating unavailability when no events are scheduled and adjust the background color in FullCalendar

In one of my projects, I am utilizing jQuery FullCalendar to schedule appointments for doctors. The doctors should be able to specify their availability between 9 AM - 5 PM on weekdays. If this is not set, the background color of the spans of time not boo ...

JavaScript function trying to send a POST request to API

I'm encountering an issue when attempting to execute an API GET request using JavaScript's built-in XMLHttpRequest function. I'm perplexed by why this functionality is failing to operate properly. function getStats(username){ const request ...

Changing the text link color on IOS can be achieved by modifying the CSS properties

Recently, I encountered an issue with the text link color of my website. While I had set the link color to red for desktop view, it inexplicably changed to blue when viewed on an iPhone. Even after trying to use !important, the problem persisted. Can som ...

The Jquery confirmation dialogue does not seem to be functioning properly within the Content Place Holder

I've encountered an issue with a JQUERY Confirm dialogue where it works perfectly fine until I place it on a page that is within a masterpage. The confirm alert pops up for a split second and disappears. window.onload = function() { $("#ehi").cli ...

Is there a way to fake a delayed reload when the webpage contains an audio element?

I have included an audio on my page which is causing it to load slowly. Below is the code snippet I am using: <div style="margin-left: 160px;"> <audio controls id="audio"> <source src="" type=&q ...

No code is appearing on the page, just a blank space

Whenever I visit this page on the web, the screen shows up as empty and I've encountered similar issues with other JavaScript pages that I've created. This makes me wonder if there might be a missing piece of code or something else causing the pr ...

Exploring the possibilities with Node.js and OpenCV

I'm experiencing difficulties with face tracking and detection using the npm opencv package. Right now, I'm attempting to draw a circle around each detected face. Below are the error details and associated files. I'm unsure if it's a b ...

Can you explain the variance between calling mongoose.Schema() and creating a new instance with new mongoose.Schema()?

Can you explain the distinction between mongoose.Schema() and new mongoose.Schema() methods? I have tried both approaches, and it seems like they yield similar results. Are there any notable differences or implications to consider? ...

Trigger an alert after a separate function is completed with jQuery

On my page, I have a function that changes the color of an element. I want to trigger an alert once this action is complete using changecolor(). However, I am unable to modify the changecolor() function due to certain restrictions. Is there a way to dete ...

Verify that the username is already in use via AJAX

Recently, I made the switch from PHP to Django and I'm finding myself a bit lost with AJAX integration. In my previous experience with PHP, I was comfortable using AJAX, but now that I'm working with Django, I'm facing some challenges. My c ...

Avoid having Vue CLI delete all files in the dist folder

As I work on my Vue project, I am facing a challenge in syncing the dist folder with Git. Previously, this process ran smoothly when using webpack. However, after transitioning to @vue/cli and creating my project with vue create myProject instead of vue in ...

A guide on navigating through an array nested within an object

I have been diving into the world of ReactJS, experimenting with different APIs to fetch and manipulate data. Currently, I am working with the Flickr API which returns data structured as "An array inside an object". { "photos": { "page": 1, "page ...

The res.render function is failing to render the view and instead, it is generating

When making a call to express/node like this: jQuery.ajax({ url : url, type: "GET", data: {names : names}, success: function(data) { console.log("ajax post success"); }, ...

Enhancing user experience: Implementing specific actions when reconnecting with Socket.io after a disconnection

I am working on a game using node.js and socket.io. The code I have written is quite simple. The game starts animating as soon as it connects to the server and continues to do so. My main concern is ensuring that the game handles network and server disco ...

Encountered an issue when attempting to access a file on the desktop using Node.js

Here is the code I am using to read a simple file from my desktop: module.exports = function (app) { app.get('/aa', function(req, res) { fs = require('fs'); fs.readFile('‪C:\\Users\\t5678 ...

JQuery datepicker not triggering Angular event

Having trouble getting Angular event to work with a jQuery datepicker. I am attempting to use the ng-change event on the jQuery date picker, but it does not seem to trigger when the date changes. Using jQuery: $('.datep').datepicker({ form ...