The fact is that in .gTable there are a lot of .forum classes and when I display it like this:

var forum_name = $(this).find('.forum').text()+'|'; 

then it turns out that all classes merge into one and at the very end is |. Screenshot -

img

Questions about Vkontakte and Discussion of programs and services look like this:

 <div class="forum"> Вопросы о ВКонтакте </div> <div class="forum"> Обсуждение программ и сервисов </div> 

In fact, should be displayed as:

Questions about VK | Discussion of programs and services |

My govnokod did not cope with this, help, please do the right thing:

  $('.gTable:last').hide(); $('.gTable').each(function() { var cat_name = $(this).find('.gTableTop').text(); var forum_name = $(this).find('.forum').text()+'|'; $(this).html('\ <div class="forum_cat_name">'+cat_name+'</div>\ <div class="forum_themes_content">\ '+forum_name+'\ </div>\ '); }); 
  • one
    So: var $ forums = $ ('. Forum'); var forum_name = []; for (var i = 0; i <$ forums.length; i ++) {forum_name.push ($ forums [i] .innerHTML.trim ()); } forum_name = forum_name.join ('|'); - ReinRaus
  • @ReinRaus ♦ and if I want to wrap a div? Have to saw through? And it would be desirable to put a ready solution into my code: / - ModaL
  • If you want to wrap a div, just do: var $ forums = $ ('. Forum div'); - ReinRaus
  • You did not understand. Like this: <div class = "test"> '+ $ (this) .find ('. Forum '). Text () +' </ div> - ModaL

1 answer 1

http://jsfiddle.net/nsnQg/

UPD : IVsevolod enhanced user version : http://jsfiddle.net/Zsp63/

  • p # forum-list WAT? - Gena Tsarinny
  • one
    The paragraph with the ID "forum-list", where the output result. You can replace it with anything, for example div. - uzumaxy
  • one
    only I think there’s no need to constantly receive text, merge with old text and assign text. Better like this: $ ('. GTable> .forum'). Each (function () {$ ('p # forum-list'). Append ($ (this). Text () + '|');}); IMHO, it will be faster and more beautiful. Yes, and $ ('p # forum-list') can be put into the variable for each - IVsevolod
  • IVsevolod, you are right, so better. - uzumaxy