Здесь я пытаюсь изменить css добавленного элемента, имеющего класс как .item, при щелчке на флажке. Что происходит здесь: когда я нажимаю на добавленный элемент, применяется css ('line-through'); вместо этого я хочу, чтобы css применялся, когда я только устанавливаю флажок.изменение css при нажатии на флажок с jquery
Я попытался запустить отдельные запросы через консоль, и он вернул правильное значение, но не отображал запись 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');
}
});
'textDecoration' должен быть' текста decoration' нет? – Callam
Это 'text-decoration', [here you go.] (Http://www.w3schools.com/cssref/pr_text_text-decoration.asp) – pol