Makudex
Makudex

Reputation: 1082

Disable html in a div

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

Answers (8)

Dag H&#248;idahl
Dag H&#248;idahl

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

divy3993
divy3993

Reputation: 5810

I would suggest simple solution to this:

&lt = less than
&rt = greater than

&lttag&gt Hello i am simple text not an HTML element &lt/tag&gt

Upvotes: 1

Payer Ahammed
Payer Ahammed

Reputation: 907

Use This PHP functoin htmlspecialchars() example:

$value = "`<b> Good </b>`";

<div id = "true"><?php echo htmlspecialchars($value); ?></div>

Upvotes: 2

guest271314
guest271314

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

sap
sap

Reputation: 343

Just try the jQuery text() method.

$('yourdiv').text(<b> Good! </b>);

Know more from here

Upvotes: 0

steves165
steves165

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

Christiaantje
Christiaantje

Reputation: 1

You should convert the html-tags to html-tags. E.g. &lt;b&gt;Good!&lt;/b&gt;

How this is done depends on the programming language your are using.

Upvotes: 0

henrik
henrik

Reputation: 133

You can use jquery text() method like this: $("content").text()

Reference: http://api.jquery.com/text/

Upvotes: 0

Related Questions