Hello,
i am very new to javascript and i am trying to write a code that wil delete
“< p >” and other tags.
after alot of struggeling i think i got the concept, however when i want to check in the browser nothing shows.
this is my code
Could you explain a little more about what you’re trying to achieve. I understand that you want to remove the <p> tag, but it’s worth knowing what happens around that. So for instance:
What happens to any content that it’s wrapped around?
What do you want to happen to the closing </p> tag? It’s worth noting that var data doesn’t contain one at the moment, but that the browser (Chrome anyway) ‘sees’ that, and closes the tag off for you.
What happens if the <p> tag has a class, id, or other attribute in it?
You’ve probably worked out by now that data in this instance is a string, but what you could do to check, is add the following on the line immediately after you declare data…
console.log(typeof data); // string
then check the browser console to see what it tells you. This is an easy way of establishing what you’re dealing with if you’re not sure, and is an invaluable debug technique when working with JavaScript.
At this point i am trying to make a simple code to understand what i am doing. Eventually i will also remove the </p> tag. My end goal is to clean up an XML file wich contains alot of these tags wich are inneccery. If i am correct it shouldn’t remove the real <p></p> tags because i used ("<" + "p" + ">")
thank you for the tips! I am at work now so at this point i cant tell you if the page you send helped but i have a break soon.
Then i will come back to you directly
Hello again.
That site you send really helped me to find the solution, so Thank you.
it seems that this does the trick
var data = "dsrufh<p>fhuseirhhjsfk<p>fwekls";
var data_new = data.replace(new RegExp('<p>', 'g'), '');