Reputation: 1374
I have one question.
I am trying to make a addClass
, removeClass
button function for after the text length > 5
or something else.
So the addClass
working fine in my code but removeClass
doesn't work. What I am missing here or what I am doing wrong here anyone can help me in this regard ?
I have tried the following code also please click for DEMO:
// Keypress for active inactive button
$(".PGA51c").on('keyup', function() {
var ID = $(this).attr('data-id');
var cm = $('#PCm' + ID);
if (cm.text.length < 5) {
$('#sev' + ID).addClass('tCo');
console.log('OK');
} else {
$('#sev' + ID).removeClass('tCo');
console.log('Not OK');
}
});
});
Upvotes: 0
Views: 161
Reputation: 20740
Use text()
instead of text
in if
condition.
$(".PGA51c").on('keyup', function() {
var ID = $(this).attr('data-id');
var cm = $('#PCm' + ID);
if (cm.text().length < 5) {
//-----^^^^^^--------------
$('#sev' + ID).addClass('tCo');
console.log('OK');
} else {
$('#sev' + ID).removeClass('tCo');
console.log('Not OK');
}
});
Upvotes: 2