Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Сравнить class (https://javascript.ru/forum/jquery/24135-sravnit-class.html)

zaymund 18.12.2011 23:21

Сравнить class
 
Беру текст из таблицы и очищаю его от пробелов..
Теперь мне нужно сравнить каждый класс и если есть совпадения то добавить им одинаковые классы coincidence..
Подскажите как лучше сделать?

Код:

var compareValue = $('.info_compare td');
  compareValue.each(function(){
          var text = $(this).text();
          text = str_replace(' ', '', text);
          text = str_replace('\t', '', text);
          text = str_replace('\r', '', text);
          text = str_replace('\n', '', text);
          text = str_replace('.', '', text);
          text = str_replace(',', '', text);
          text = str_replace('!', '', text);
          text = str_replace('?', '', text);
          text = 'compare_' + text.toLowerCase();
          var td = $(this);
          td.addClass(text);
          console.log(td);
          }


Serg_pnz 19.12.2011 10:59

Небольшое замечание:
Используйте regexp и спецсимвол \s для очистки всех пробельных символов http://wdh.suncloud.ru/js05.htm
Опять же в эту "экспу" можно включить и другие символы, как то тчк, зпт и проч. Пожалейте компутер пользователя ;)


Часовой пояс GMT +3, время: 07:30.