V
V
Vlad Bazarov2015-11-17 01:00:58
JavaScript
Vlad Bazarov, 2015-11-17 01:00:58

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" );
  };
});


Thanks for the help!

UPD
I understand that I may be going too far, but I'm completely tired of fighting with one problem on the site. If you help me, I will be extremely grateful.
loveyou.ua/igrushki-podushki/?page=2

If you pay attention, some products with a long name (two lines) rise above their "brothers". This should not be.

I tried to change position to absolute, but then you won't set margin.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
elhini, 2015-11-17
@vlad1337

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'.

V
Vitaly Vitrenko, 2015-11-17
@Vestail

$(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 question

Ask a Question

731 491 924 answers to any question