Answer the question
In order to leave comments, you need to log in
Why is the jQuery function not working?
Good evening everyone!
I wrote a simple function to check the number of characters in a sentence, and if the number is greater, then the font is reduced. However, she will work. Can you tell me what is the problem?
$(document).ready(function(){
if ($('.name').val().length=>22) {
$(this).css( "font-size", "15px" );
};
});
Answer the question
In order to leave comments, you need to log in
The val() method is used to get the value of form elements like input, select, textarea. If you want to get the contents of a regular element, you need to use the text() method. Moreover, inside the condition, you use this as an element, which in this case is a reference to the document element, and you yourself probably meant an element with a class of 'name'.
$(document).ready(function() {
var name = $('.name');
if (name.text().length >= 22) {
name.css("font-size", "50px");
};
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question