I want to remove the end tag of a given HTML string. I get the HTML string from the document like so:
var front = $('<div>').append($(clean_copy).contents().remove().end()).remove().html();
I now want to remove the </div> from the below:
<div id="div1" style="font-size: 20px"></div>
I am really rusty with regex but I want to try something like this:
console.log("Remove End: " + front.replace('/<(/)?div([^>]*)>/g', ''));
The above doesn’t work, how can I remove any tag? Also some strings may not have an end tag.
try
front.replace(/<\/div>$/)It replaces your div.
If you like to replace any last end tag use this
front.replace(/<\/\S+>$/)