Reputation: 1082
I wanted to disable HTML in a div simply because I want just a plain text to be shown inside a div.
If you retrieve a data from the DB and it's value is <b> Good! </b>
which is equivalent to Good! in HTML. Now what I want is that, I wanted to show the word <b> Good! </b>
(without html style) and not the Good! (with html style). Any method would do, whether through javascript or jquery as long as it plays the same role.
Example:
$value = "`<b> Good </b>`";
<div id = "true"><?php $value; ?></div>
And the div would simply have an output like this: <b> Good </b>
How could I do that? Any help would be much appreciated. Thanks
Upvotes: 1
Views: 124
Reputation: 8345
What you're attempting, is to whitelist some html tags in the input. See for example the answers to this question for how to do it in php.
Upvotes: 0
Reputation: 5810
I would suggest simple solution to this:
< = less than
&rt = greater than
<tag> Hello i am simple text not an HTML element </tag>
Upvotes: 1
Reputation: 907
Use This PHP functoin htmlspecialchars()
example:
$value = "`<b> Good </b>`";
<div id = "true"><?php echo htmlspecialchars($value); ?></div>
Upvotes: 2
Reputation: 1
Tried utilizing textarea
element ?
$("textarea").html("<b> Good! </b>")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<textarea></textarea>
Upvotes: 0
Reputation: 343
Just try the jQuery text() method.
$('yourdiv').text(<b> Good! </b>);
Know more from here
Upvotes: 0
Reputation: 104
Simplest solution would be to add it to a Dom element then return the text.
Something like this.
Var div = document.createElement('div');
Div.innerhtml = ' good';
Var res = div.innerText;
In this case res would be equal to 'good'.
Upvotes: 0
Reputation: 1
You should convert the html-tags to html-tags.
E.g.
<b>Good!</b>
How this is done depends on the programming language your are using.
Upvotes: 0
Reputation: 133
You can use jquery text() method like this: $("content").text()
Reference: http://api.jquery.com/text/
Upvotes: 0