I have set up a little web application where you add post-its to a page. It's just a project to help better learn JavaScript/jQuery and it seemed like an appropriate project (I'm new to JS/jQuery).
This is the fiddle: http://jsfiddle.net/mitchbregs/mWaPz/
I found this website: http://www.hscripts.com/scripts/JavaScript/remove-html-tag.php
I implemented the code as so:
function stripHTML(){ var re = /(<([^>]+)>)/gi; for (i=0; i < arguments.length; i++) arguments[i].value=arguments[i].value.replace(re, "") }
and it still didnt work.
The problem: I need it so that when somebody inputs text into the textarea, if they input something like this "<b>Hi</b>
" it would strip the "<b>
" tag from the input and leave just the text.
If someone could help me out this it would be great.. Thanks!
You have three issues: One is that the method is not returning properly (that's the fault of whoever wrote it). Next is that you are defining the method within $(document).ready()
, so it is not able to be found (at least in Chrome). Third, you are not calling it the right way (onSubmit
will never be used here).
I've used @Joao's method (so you should upvote his answer) and used this method, moved outside of the ready()
function:
function stripHTML(str){
var strippedText = $("<div/>").html(str).text();
return strippedText;
}
And also called it here:
var post = stripHTML($(".text_input").val())
Here is the working fiddle: http://jsfiddle.net/ee3MH/
var textAreaValue = "text <br /> more text";
var strippedText = $("<div/>").html(textAreaValue).text();
And here's a Fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With