Last Updated : Jan 1, 2023
As, there are methods like replace(), textcontent() and innerText(). These all are inbuilt or predefined function with which we can remove tags.
In this article we are going to use replace() to remove tags from string. In next sessions we will understand other methods and understand how they work. Let us see the codes below to understand replace().
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
- Here, we create a function with name removeHtml and pass an argument string there. If our string is null or empty it return false else the function runs.
- After that we use our function removeHtml that we created above and pass a string inside this.
- We you see the output you see only Hello World! You see that the html tags that we created there gets removed. We hope that you understand the codes properly with help of these steps.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.