There are view tags on the page.

[indie][/indie] [futurama][/futurama] 

It is necessary by means of javascript (jquery) to find similar tags and replace each with html tags:

 [indie]содСрТимоС[/indie] => <span style=" font-family: 'Indie', cursive">содСрТимоС</span> [futurama]содСрТимоС[/futurama] => <span style=" font-family: 'Futurama', sans-serif">содСрТимоС</span> 
  • Is it in school now such computer science problems? - Sergey

1 answer 1

Here is an example, the result is displayed in the console

 var search = new Array( "\\[indie]?(.*?)\\[/indie]", "\\[futurama]?(.*?)\\[/futurama]" ); var replaceTo = new Array( '<span style="font-family: \'Indie\', cursive">$1</span>', '<span style="font-family: \'Futurama\', sans-serif">$1</span>' ); var str = '[indie]Indie text[/indie][futurama]Futurama text[/futurama]'; console.log('Π‘Ρ‹Π»ΠΎ: ', str); for (i = 0; i < search.length; i++) { str = str.replace(new RegExp(search[i], 'g'), replaceTo[i]); } console.log('Π‘Ρ‚Π°Π»ΠΎ: ', str); 

  • And how does this work with divs? If a div with the class .post-content, it can contain both tables, and p, and any other html tags. If I try to replace str with a selector, jquery produces $ ('...') errors. Replace is not a functon. - morganchees
  • @morganchees .replace works with strings. $('') is a jQuery object, not a string. You can take $('.post-content').html() - will output a string with everything in the .post-content block. - Vasily Barbashev
  • thanks, works :) - morganchees