javascript - A regex to identify spans with given class names -


i in process of writing custom bbcode editor (i have excellent reasons doing , not using readymade effort) generates, amongst other things html markup such as

<span class='classname'>...</span> 

all of done , works well. however, need reverse transformation html bbcode time-to-time need identify spans use given classname. example

<span class='classnamea' style='font-family"arial"'>span content</span> can convert bbcode markup  [font=arial]span content[/font] 

i aware of dangers of using regexs parse old html , not intent. need reverse parse own html tags - else passing through bbcode editor display.

to cut long story short - no regexs particularly require lookaheads etc. appreciate creating javascript regex job.

i suggest either use benjamin's suggestion , store bb codes somewhere.

alternatives regex innerhtml or textcontent

document.queryselectorall("span.classnamea"); 

or

document.getelementsbyclassname("classnamea"); 

or if use jquery can use

$(".classnamea").text() 

and

$(htmlstring).find(".classnamea").each(function() {   var text = $(this).text();  }); 

without creating dom


Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

java - What is the difference between String. and String.this. ? -