Get the text without HTML tags by javascript
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts: 106
Get the text without HTML tags by javascript
Hi,
I have a Div with some content and other html tags inside.
How can I get all the text content of this Div, without the html tags?
I ussed innerHTML property, but gets the tags too.
This is what i tried:
Code: Select all
<div id="d_id">
Some content ...
<p>Other html element.</p>
<span>Text in Another html tag</span>
</div>
<script>
var get_text = document.getElementById('d_id').innerHTML;
alert(get_text);
</script>
Admin
You can use this:
Code: Select all
<div id="d_id">
Some content ...
<p>Other html element.</p>
<span>Text in Another html tag</span>
</div>
<script>
var get_elm = document.getElementById('d_id');
// innerText for IE, textContent for other browsers
var get_text = get_elm.innerText || get_elm.textContent;
alert(get_text);
</script>
Or, if you use jQuery:
Similar Topics
-
Function to convert BBcode in HTML tags
Scripts from this website
First post
Best Admin first off all how are you doing...
Recently I`m busy to improve my comment-system.
But Function to convert BBcode in HTML tags
I...
Last post
Hello,
I'm fine, thanks.
The formatBBcode() function converts bbcode tags from a string (such as: text and text ) into html tags...
-
How to get text from javascript alert box
JavaScript - jQuery - Ajax
First post
Good evening (dutch-time) I have a javascript what can copy text to a clip-board + it has a button to show the item-list in a alert-box.
But can`t...
Last post
Thanks for the support I tried already things with history + f_print
also studied those a little before I asked coursesweb but I shall
when my head...
-
Javascript add different text to each minute of hour
JavaScript - jQuery - Ajax
First post
Hello Coursesweb I`m unknown with javascripts ????
I would like to add function minutes to this script
on each minute an diferent text added to...
Last post
Hello,
Try the following script.
<div id='addtxtmin' style='color:#00d; font-size:20px; font-weight:700'></div>
<script>
const...
-
Adding HTML content from javascript /iQuery into a form
JavaScript - jQuery - Ajax
First post
For day`s i`m busy to improve my comment system
& no I`m ready to place a url extractor but I hope
you can support me by this-one....
I want...
Last post
It depends where you want to add the html content from javascript in the form, on the beginning, or at the end after other elements.
Se the: 2....
-
Hide element if data contains specific text
HTML - CSS
First post
Is there a possibility to hide HTML elements if the 'data-' attribute contains a specific piece of text?
For example: Hide the Divs that it's data...
Last post
You can do this with either CSS or Javascript.
CSS:
/* with specified elements */
div {
display: none;
}
/* or global */
{
display: none;...