Here I'm trying to change the css of appended item having class as '.item', on click into checkbox . What's happening over here is: when I'm clicking the added item the css('line-through') is applied; instead I want css to be applied when only I click checkbox.
I tried running the individual queries via console and it returned correct value but its not displaying the write css.
function entervalue()
{
var text = $('#inputext').val();
$("#list").append('<div class="item"> <input type="checkbox"> ' + text + '</div>');
$("#inputext").val('');
}
$(document).ready(function(){
$('#inputext').keyup(function(b)
{
if (b.keyCode===13)
{
entervalue();
}
})
});
$(document).on('click', '.item', function() {
if ($(this).css('textDecoration') == 'line-through')
{
$(this).css('textDecoration', 'none');
}
else
{
$(this).css('textDecoration', 'line-through');
}
});
body {
font: 14px 'Helvetica Neue';
line-height: 1.4em;
background: #f5f5f5;
color: #4d4d4d;
margin: 0 auto;
}
#inputext {
background: white;
font-size: 42px;
margin-left: 2%;
margin-top: 1%;
position: fixed;
border-style: inset;
border-color: floralwhite;
width: 26%;
}
#app{
background-color: aliceblue;
width: 72%;
height: 70%;
border-bottom-style:inset;
border-width: thick;
border-radius: 3%;
margin-left: 13%;
margin-top: 19%;
}
#item1{
font-weight: 500;
}
.item{
font-size: 20px;
border-bottom: solid darkcyan;
margin-bottom: 5%;
margin-top: 6%;
margin-right: 3%;
margin-left: -5%;
}
.maincontent{
background-color: darkseagreen;
margin-top: 6%;
margin-left: 36%;
height: 60%;
width: 30%;
position: fixed;
border-style: groove;
border-width: thick;
border-radius: 5%;
}
.strikeThrough{
text-decoration:line-through;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="maincontent">
<input type="text" id="inputext" placeholder="todos"/>
<div id="app">
<ul id="list">
</ul>
</div>
</div>
function entervalue()
{
var text = $('#inputext').val();
$("#list").append('<div class="item"> <input type="checkbox"> ' + text + '</div>');
$("#inputext").val('');
}
$(document).ready(function(){
$('#inputext').keyup(function(b)
{
if (b.keyCode===13)
{
entervalue();
}
})
});
$(document).on('click', '.item', function() {
if ($(this).css('textDecoration') == 'line-through')
{
$(this).css('textDecoration', 'none');
}
else
{
$(this).css('textDecoration', 'line-through');
}
});
textDecorationshould betext-decorationno?text-decoration, here you go.