Quick question, If I want to document some code on a basic HTML and put that within a CODE tag, how can I quickly convert the code between those tags when the page renders to display properly? I know I can write a javascript find and replace and search through the string over and over until its done replacing all the characters, but is there a better way?
Or, is there a jQuery way to do it if I need to use javascript?
Quick question, If I want to document some code on a basic HTML and put that within a CODE tag, how can I quickly convert the code between those tags when the page renders to display properly? I know I can write a javascript find and replace and search through the string over and over until its done replacing all the characters, but is there a better way?
Or, is there a jQuery way to do it if I need to use javascript?
Share Improve this question edited Jun 1, 2009 at 19:00 GEOCHET 21.3k15 gold badges77 silver badges99 bronze badges asked Jan 26, 2009 at 15:45 UserUser 3,7926 gold badges29 silver badges23 bronze badges 1- Can you explain what you mean when you say 'display properly'? – ForYourOwnGood Commented Jan 26, 2009 at 16:04
2 Answers
Reset to default 7I think the <code>
tag is more for displaying with a certain font, rather than layout. <code>
seems to just use a monospaced font.
You might be looking for the <pre>
tag (for pre formatted). That will preserve line breaks and spaces.
Unless the code you are trying to display is HTML code itself, then I think you'd have to change all the <
's to <
's ahead of time
Sounds like you may be looking for syntax highlighting. Take a look at google's syntax highlihter