One of the most useful things you can do with the JavaScript Code to write & #112
- Add a SCRIPT Declaration in the HEAD section of your HTML document. The SCRIPT tag defines a client-side write & #112 t, such as JavaScript. Your SCRIPT tag must have its "type" attribute to "text/javascri & #112 t", so that the entire SCRIPT Declaration should be as follows: (where the JavaScript code goes between the two marks). the
- Define a JavaScript function that a string as a parameter. This string parameter contains the HTML Code you will convert to text only. the
- Create a temporary DIV element in JavaScript function with the "createElement ()" method. the
- Assign your function a string parameter to your temporary DIV's "innerHTML" attribute. the
- Create a temporary string variable in your function. the
- you Grab the plain text content of your temporary DIV with the "textContent" and "innerText" attributes and assign them to your temporary string variable. Due to cross-browser compatibility issues, both "textContent" and "innerText" in some web browsers and undefined in others, but the one or the other will be defined in all versions of all popular browsers. the
- Enter the value held by your temporary string using a "return" statement. This returns the clear-text value of your converted HTML.
How to: Convert HTML to plain Text in Javascript
One of the most useful things you can do with the JavaScript Code to write & #112
- Add a SCRIPT Declaration in the HEAD section of your HTML document. The SCRIPT tag defines a client-side write & #112 t, such as JavaScript. Your SCRIPT tag must have its "type" attribute to "text/javascri & #112 t", so that the entire SCRIPT Declaration should be as follows: (where the JavaScript code goes between the two marks). the
- Define a JavaScript function that a string as a parameter. This string parameter contains the HTML Code you will convert to text only. the
- Create a temporary DIV element in JavaScript function with the "createElement ()" method. the
- Assign your function a string parameter to your temporary DIV's "innerHTML" attribute. the
- Create a temporary string variable in your function. the
- you Grab the plain text content of your temporary DIV with the "textContent" and "innerText" attributes and assign them to your temporary string variable. Due to cross-browser compatibility issues, both "textContent" and "innerText" in some web browsers and undefined in others, but the one or the other will be defined in all versions of all popular browsers. the
- Enter the value held by your temporary string using a "return" statement. This returns the clear-text value of your converted HTML.
How to: Convert HTML to plain Text in Javascript
By Howtodotips
One of the most useful things you can do with the JavaScript Code to write & #112