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');
}
});
});
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');
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.