Hello

Html Chunk:

<a class="class_link" href="">хатха-йога</a> 

A piece of js:

 if ($('.class_link').text() == "хатха-йога"){ alert("good"); } 

Why does not display alert?

After the 9th comment: laid out the full script: http://jsfiddle.net/eCdLt/3/ if I zoomed out also in my own place - the condition does not work, turned off all the scripts except my own and jquery.

I do not get it

upd Found what's wrong. The problem with the encoding. In the case of English letters works. Thanks guys. Pause for now

upd Does not work on the live site console.log ("hatha yoga"); console.log ($ ('. class_link'). text ()); - in both cases "hatha yoga" is displayed. See website: yogaclass.pro

Script: http://yogaclass.pro/assets/templates/yogaclass/js/script.js

Strings

  console.log($('.class_link').text()); console.log("хатха-йога"); if ($('.class_link').text() == "хатха-йога"){ alert("good in case of using jQuery"); } var a = "хатха-йога"; if (a == "хатха-йога"){ alert("good in case of using definite variable"); } 

UPD Corrected script encoding, as well as jQuery encoding. In the case of the introduction of the variable a, it works; if the text is taken by the script, it does not work.

  • one
    jsfiddle.net/eCdLt - works the same - RubaXa
  • one
    wrap the script in the code $ (document). ready (function () {}) the problem is most likely precisely this - mountpoint
  • I do not understand why there is no comparison. This shows: alert ($ ('. Class_link'). Text ()); - olegall
  • script wrapped: $ (window) .load (function () { - olegall
  • @olegall, sorry for the stupid question: did you connect the jquery library? - mountpoint

2 answers 2

I will write the answer.

instead of accessing $ ('. class_link') directly, you need to refer to

 this.$el; 

in approximately the same way:

 switch (this.$el.text()) { case "хатха-йога": this.title = 'Занятие состоит из статических, динамических и дыхательных упражнений, которые в совокупности оказывают положительное воздействие на центральную нервную систему, улучшают кровообращение, укрепляют порно-двигательный аппарата и обеспечивают слаженную работу всех систем организма! Заниматься по системе хатха-йоги могут люди с любым уровнем подготовки!'; break; case "йога-зарядка": this.title = 'Утренний комплекс хатха-йоги с элементами суставной гимнастики, направленный на повышение общего тонуса организма. Заменяет кофе!!!'; break; case "перинатальная йога": this.title = 'Йога для женщин, находящихся на различных сроках беременности. Занятия в этот период помогут будущей маме облегчить дискомфорт, вызванный токсикозом, избавиться от болей в спине и ногах, укрепить мышцы абдоминальной области, и области малого таза, что обеспечит наиболее комфортные роды, специальные дыхательные упражнения помогут восстановить кислородный баланс, необходимый для правильного развития малыша. Практикуя йогу регулярно, женщина обретает внутреннее равновесие и способность справляться со стрессами современного мегаполиса)))'; } 

  • one
    ॐ - in the Hindu and Vedic traditions - sacred sound, the original mantra. Often interpreted as a symbol of the divine trinity of Brahma, Vishnu and Shiva, the quintessence of the Word. In accordance with the Vedic heritage, it is believed that the sound of om was the first manifestation of the non-manifest Brahman, which gave rise to the perceived Universe, caused by the vibration caused by this sound. - ferrari
  • @ Oleg B, what did you mean by that? - zb '
  • You have completed your answer with this symbol! - ferrari
  • 2
    Yes, I only meant that, thanks to universal enlightenment, I grasped the essence of the problem, and I also express unity with the questioner and at the same time I expressed the assurance that my desire to help him sincerely and I personally approve of his activities in a specific moment of time. - zb '

$('.class_link').text() - initially does not imply a single value, there may be a lot of classes on the page, so you get an array of objects in the response, even if it is one there.

You need to either go to id, or check the value through each. It may even work and this option $('.class_link')[0].text()