idude
idude

Reputation: 4922

Jquery HTML Method

I'm using JQuery to work on a project and am having some trouble with the html() method. Is there any way that the method can ignore certain tags in the text? For example if the string is

"A paragraph can be started with a <code><p><code> tag"

How can I make it so that the code tag will be interpreted but the p tag with it's brackets will not? If the solution requires something beside Jquery, still let me know.

Thanks in advance!

Upvotes: 0

Views: 100

Answers (5)

RedsDevils
RedsDevils

Reputation: 1433

The following is what I found using jquery functions. :)

<script>    
 $( "div" ).html("A paragraph can be started with a <code>" );
 $( "div" ).append( $("<code>").text("<p>"));
 $( "div" ).append("<code> tag.");  
</script> 

Upvotes: 0

LearnerBeware
LearnerBeware

Reputation: 73

First off you havent enclosed your code tag '</code>'

If you are trying to print html in plain text try and enclose the words in <xmp> </xmp> tags instead

Your Case:

"A paragraph can be started with a <xmp> <p> </xmp> tag"

or even:

<xmp>A paragraph can be started with a <p> tag</xmp>

Upvotes: 1

Hendry Tanaka
Hendry Tanaka

Reputation: 464

Try this:

Use symbol &lt; and &lt;/ &gt; for closing tag like this. Example : "A paragraph can be started with a <p> Tutorial </p> tag"

&lt; is < , &gr; is >. Combining both of them will create a bracket as tag that will not interpreted by browser as a html tag.

Bonus: DEMO. Easy to use.

Upvotes: 2

Jonathan
Jonathan

Reputation: 113

Try this but not sure if support all browsers. See Fiddle

A paragraph can be started with a <xmp> <p> </xmp> tag

Upvotes: 1

Kull
Kull

Reputation: 45

"A paragraph can be started with a <code><p>...</p></code> tag"

try this

Upvotes: 1

Related Questions