Thanks! A quick note about the regexp: the “i” isn’t needed here because there are no characters to be case-insensitive about. However, it does exactly what you want either way.
I saw your contact form and i must say i love it!
Do you have a tutorial or something like that? It’s a wonderful one :)^
Hope to hear some news of you,
the /i for case insensitivity is definitely recommended.
When using contenteditable, IE produces upper case tags, mozilla would only create lower case… To strip those you need it case insensitive.
var text = ‘[$ ssIncludeXml(docName,"wcm:root/wcm:element[@name='innerpage_content']/text()”) $]’;
var StrippedString = text.replace(/(]+)>)/ig,”");
where ‘[$ ssIncludeXml(docName,"wcm:root/wcm:element[@name='innerpage_content']/text()”) $]’
is Idoc script that brings a block of HTML from a placeholder. But i am getting “unterminated string literal” Error at first line.
What i want to do is to remove or strip all HTML tags and to get plain text out of that markup.
Was wondering how this would be implemented if I only wanted to remove the href tags from a string of text, instead of removing all the tags? I’m trying to retrieve a page of text from a website but I only want the plain text with the formatting tags (p, ul, li).
Hope this makes sense, thanks in advance.
Your script works great! Cheers!
this is so cool , i like it
/**
* isArray
*
* @param mixed input
* @return bol
*/
function is_array(obj) {
if (obj.constructor.toString().indexOf(‘Array’) == -1) {
return false;
}
return true;
}
/**
* stripTags
*
* @param mixed input
* @parm mixed output
*/
function strip_tags(input) {
if (input) {
var tags = /(]+)>)/ig;
if (!is_array(input)) {
input = input.replace(tags,”);
}
else {
var i = input.length;
var newInput = new Array();
while(i–) {
input[i] = input[i].replace(tags,”);
}
}
return input;
}
return false;
}
function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText;
}
This was even better for my needs. No issues with special characters etc…
hey!!!..this is so ridiculous..
Thank you for great example
Thanks, this does exactly what I need (and so concisely, too!)
Thanks! A quick note about the regexp: the “i” isn’t needed here because there are no characters to be case-insensitive about. However, it does exactly what you want either way.
your code works perfectly.. Thanks.. :)
Nice, but the parentheses are unnecessary.
.replace(/<[^>]+>/ig,”");
Hi :)
I saw your contact form and i must say i love it!
Do you have a tutorial or something like that? It’s a wonderful one :)^
Hope to hear some news of you,
A french reader,
Florian
Thank for script :)
@Ricard: If you want to make a copy of the contact form, just view source or save this page to you local ;)
Words like a charm!!
beautul site thank you for great example
the /i for case insensitivity is definitely recommended.
When using contenteditable, IE produces upper case tags, mozilla would only create lower case… To strip those you need it case insensitive.
Hi
I have following code:
var text = ‘[$ ssIncludeXml(docName,"wcm:root/wcm:element[@name='innerpage_content']/text()”) $]’;
var StrippedString = text.replace(/(]+)>)/ig,”");
where ‘[$ ssIncludeXml(docName,"wcm:root/wcm:element[@name='innerpage_content']/text()”) $]’
is Idoc script that brings a block of HTML from a placeholder. But i am getting “unterminated string literal” Error at first line.
What i want to do is to remove or strip all HTML tags and to get plain text out of that markup.
Kindly let me know if there is any solution.
Thanks
works great but doest strip whitespaces….
Thank you! It was very useful for me and I think that is useful for everyone.
Thank you again!
Yeah, this solution removed all sorts of HTML, paragraph, line breaks, in-line styles etc etc
This does not works for IE. Please provide solution to strip tag in javascript that works for all browsers
Thanks for this script
It work greate
great script its working
thanks
i am trying it on
var message;
firstName = document.getElementById(“username”).value;
if (firstName == null || firstName == “” || firstName == NaN || firstName == “First Name”) {
message = “Please Add some name.”;
document.body.insertAdjacentHTML(“BeforeEnd”, “” + message + “”);
}
else {
if (document.getElementById(“myMessage”)) {
debugger;
arguments = document.getElementById(“myMessage”).value.replace(/(]+)>)/ig, “”);
}
}
but it is not working and saying
cannot call method ‘replace’ of undefined
Was wondering how this would be implemented if I only wanted to remove the href tags from a string of text, instead of removing all the tags? I’m trying to retrieve a page of text from a website but I only want the plain text with the formatting tags (p, ul, li).
Hope this makes sense, thanks in advance.
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.