jQuery遍历具有通用类的HTML元素,并比较与内容给出的字符串

Lay*_*nee 2 html jquery class string-comparison

在jQuery函数中,我需要遍历具有相同类的几个HTML元素,并在每次迭代中将特定字符串与这些元素的内容进行比较。

谁能给我一些技巧来做到这一点?

Ras*_*ari 5

尝试这个:

$.each($('.your-class-name'), function() {
      if($(this).text() == 'your-text')
               console.log('yes');
      else
               console.log('no');
});
Run Code Online (Sandbox Code Playgroud)