Below is some code I've been messing with that basically takes a string containing HTML and removes elements with class="normal". To do so, the prototype function removes all line breaks, etc before it actually removes an element and all of its inner contents. The below code works as expected:
var msg = '<p>Keeping this paragraph</p>\n<p class="normal">Removing this paragraph<br>\n</p>\n<p class="normal">Another paragraph to remove<br>\n</p>';
String.prototype.takeOut = function() {
return this.replace(/(\r\n|\n|\r)/gm," ")
.replace(/<p[^>]*class="normal"[^>]*>(.*?)<\/p>/g, '');
};
alert(msg.takeOut());
My problem is that I want to pass an argument through the method like so..
msg.takeOut('normal')
and let the prototype function take that argument to remove elements with whatever class we want like so:
msg.takeOut('foo')
msg.takeOut('bar')
Here is an example with more details:
I know that "new RegEx()" might be the solution, but how do I incorporate that into what already works? No jQuery please! Thanks for your help!
Admin content here
User content here
As the emails are being sent out in the back-end, I need something that says "if its a user, remove admin stuff.. and vice-versa". Would I be better off not using classes and instead trying something like a square bracket shortcode? Ex: [admin]admin stuff[/admin] [user]userstuff[/user]. – sdawson Jul 03 '15 at 20:10