Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to see the source code of a particular html tag by onClick() javascript without showing its css?
    text
    copied!<p>Hi everyone, here am trying to display the source code of a particular div by onclick </p> <p>javascript function. But the result am getting is , when i click on the div, am seeing the </p> <p>whole source code though am trying to make only the particular source code of a div to get</p> <p>displayed. anyone please highlight me what am doing wrong here..! and what to do to make </p> <p>it work in the way its expected. </p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript"&gt; function viewsource(){ var oldHTML = document.getElementById('para').innerHTML; var newHTML = "" + oldHTML + ""; var newHTML = newHTML.replace(/&lt;/g,"&amp;lt;"); var newHTML = newHTML.replace(/&gt;/g,"&amp;gt;"); var newHTML = newHTML.replace(/\t/g,"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"); document.getElementById('para').innerHTML = newHTML; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p id='para'&gt;&lt;strong&gt;This is my &lt;span style="border: 1px solid #ccc;"&gt;test text&lt;/span&gt; to check if it works&lt;/strong&gt;&lt;/p&gt; &lt;input type='button' onclick='viewsource()' value='View Source'/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Additional notes: </p> <p>In the above code, when the button is clicked, the paragraph tag with the id of para will display...but it shows its css too. I want to display only the html tag without the css style attribute.</p> <p>I don't want the content using innerHTML but i want the whole div including with the div id.(eg.)<code>&lt;div id='softros'&gt;&lt;img src='/images/bgrade.jpg' /&gt;&lt;/div&gt;</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload