Displays the html tags without rendering on a webpage

CK CK 3788 
Created at  
352 0 0
Following code display the html tags without additonal web page rendering.

<script type="text/javascript">
function firstMethod()
{
  var str = document.getElementById("tbl").innerHTML.replace(/[<]/g,'&lt;');
  str = str.replace(/[>]/g,'&gt;');
  document.getElementById("displayHTML").innerHTML = str;
}
function secondMethod()
{
  document.getElementById("displayHTML").innerText = document.getElementById("tbl").innerHTML;
}
</script>

.
.
.

<body>
  <div id="displayHTML"></div>
  <table border="1" id="tbl">
    <tr>
      <td style="width: 100px">
        1</td>
      <td style="width: 100px">
        2</td>
      <td style="width: 100px">
        3</td>
    </tr>
    <tr>
      <td style="width: 100px">
        4</td>
      <td style="width: 100px">
        5</td>
      <td style="width: 100px">
        6</td>
    </tr>
    <tr>
      <td style="width: 100px">
        7</td>
      <td style="width: 100px">
        8</td>
      <td style="width: 100px">
        9</td>
    </tr>
  </table>
  <input type="button" value="use conventional method" onclick="firstMethod()" />
  <input type="button" value="use serkan's method" onclick="secondMethod()" />
</body>


This is a good example of using javascript innerText property which is not
as popular as innerHTML property.
Tags Collapsible Table Expand Table File Attributes HTML Javascript getElementById Facebook X
Comments 0
Similar posts
  1. Javascript based query parser for AJAX application
    565
  2. To hide/show area of web page without re-loading a page
    1,021
  3. To get web browser capability
    525
  4. To compare two HTML tables on web page in real time
    515
  5. Photo thumbnail viewer implemented in javascript
    487
  6. Javascript Confirmation
    593
  7. Javascript Prompts
    450
  8. How to know browser version in javascript ?
    443
  9. How to know the browser name in Javascript ?
    639
  10. Select All, None, Invert checkbox
    506
  11. Photoshop script programming in Javascript
    531
  12. How to remove HTML tags in text string?
    405
  13. Simple RSS Reader based on javascript
    502
  14. How to find the ip address of a client machine from a web application?
    518
  15. Clipboard copy function working
    3,368
  16. IFRAME Auto Resize in IE, FireFox by Javascript
    455
  17. How to include Javascript from anonther ?
    410
  18. Javascript based Browser Sniffing
    433
  19. Javascript based Regular Expression Tester
    374
  20. Two useful string functions - substr & substring
    406
  21. Is there URLEncode function in Javascript ?
    393
  22. Move window
    548
  23. How to calculate page loading time ?
    359
  24. Number Of Vists
    511
  25. Add Message On Mouse Traling
    2,557
  26. Tooltip
    408
  27. Document Fader
    346
  28. Book Mark This Site
    405
  29. Icon Coupled Url
    427
  30. Button That Will Close The Browser Window
    350
  1. IndexNow for better SEO
    317
  2. Enhancing SEO for Single Page Applications: Implementing Dynamic URL Updates
    1,039
  3. Method to ignore JavaScript Errors globally instead of try... catch for each of cases
    969
  4. Method to catch the browser console log and errors for remote web debugging
    2,171
  5. Atlassian Jira Ticket API Response Example
    2,765
  6. Three different type of Word-Wrap options in HTML CSS
    1,183
  7. JavaScript code to load XML Document
    601
  8. Creating a Pinterest-Style Card Layout with Bootstrap and Masonry
    595
  9. Equal Height Blocks in Bootstrap with JavaScript
    710
  10. Copy text to clipboard in Javascript
    1,715
  11. To block copy & paste on your blog content
    901
  12. Shake your browser window by Javascript
    935
  13. Photoshop script programming in Javascript
    531
  14. To compare two HTML tables on web page in real time
    515
  15. To hide/show area of web page without re-loading a page
    1,021
  16. Javascript based query parser for AJAX application
    565
  17. To get web browser capability
    525
  18. Photo thumbnail viewer implemented in javascript
    487
  19. Javascript Confirmation
    593
  20. Javascript Prompts
    450
  21. How to know browser version in javascript ?
    443
  22. How to know the browser name in Javascript ?
    639
  23. Select All, None, Invert checkbox
    506
  24. Simple RSS Reader based on javascript
    502
  25. How to find the ip address of a client machine from a web application?
    518
  26. Put Date Time on HTML
    551
  27. IFRAME Auto Resize in IE, FireFox by Javascript
    455
  28. How to elimiate the "Restore Previous Session" dialog when FireFox 2.0 starts
    409
  29. How to include Javascript from anonther ?
    410
  30. Javascript based Browser Sniffing
    433
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    39
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    582
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    216
  30. Understanding Data Lineage
    260