<p>I want to use javascript to insert some elements into the current page.
Such as this is the original document:
&lt;p&gt;Hello world!&lt;/p&gt;</p>

<p>Now I want to insert an element in to the text so that it will become:</p>

<p>&lt;p&gt;Hello &lt;span id=span1&gt;new&lt;/span&gt; world!&lt;/p&gt;</p>

<p>I need the span tag because I want to handle it later.Show or hide.
But now problem comes out, if the original page has already defined a strange CSS style on all &lt;span&gt; tags, the "new" I just inserted will not appear to be the same as "Hello" and "world". How can I avoid this? I want the "new" be exactly the same as the "Hello" and "world".</p>

[{'answer_id': 80228, 'author': 'Sev', 'author_id': 83819, 'author_profile': 'https://Stackoverflow.com/users/83819', 'pm_score': 0, 'selected': False, 'text': '<p>Include the class definition that\'s defined in CSS on your JavaScript version of the <code>&lt;span&gt;</code> tag as well.</p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;span class="class_defined_in_css"&gt;\n</code></pre>\n\n<p>(where this <code>&lt;span&gt;</code> tag would be part of your JavaScript code.)</p>\n'}, {'answer_id': 80231, 'author': 'dreamlax', 'author_id': 10320, 'author_profile': 'https://Stackoverflow.com/users/10320', 'pm_score': 0, 'selected': False, 'text': '<p>Why not give the paragraph an id and then use Javascript to add the word, or remove it, if necessary? Surely it will retain the same formatting as the paragraph when you insert the word "new", or change the contents of the paragraph entirely.</p>\n'}, {'answer_id': 80251, 'author': 'Jason Bunting', 'author_id': 1790, 'author_profile': 'https://Stackoverflow.com/users/1790', 'pm_score': 1, 'selected': False, 'text': '<p>Well, I don\'t know how married you are to using a &lt;span&gt; tag, but why not do this?</p>\n\n<pre><code>&lt;p style="display: inline"&gt;Hello &lt;p id="myIdValue" style="display: inline"&gt;new&lt;/p&gt; World&lt;/p&gt;\n</code></pre>\n\n<p>That way the inserted html retains the same styling as the outer, and you can still have a handle to it, etc. Granted, you will have to add the inline CSS style, but it would work.</p>\n'}, {'answer_id': 80262, 'author': 'Prestaul', 'author_id': 5628, 'author_profile': 'https://Stackoverflow.com/users/5628', 'pm_score': 1, 'selected': False, 'text': '<p>The only way to do this is to either modify the other spans to include a class name and only apply the styles to spans with that class, or override the styles set for all spans for your new span.</p>\n\n<p>So if you\'ve done:</p>\n\n<pre><code>span {\n  display: block;\n  margin: 10px;\n  padding: 10px;\n}\n</code></pre>\n\n<p>You could override with:</p>\n\n<pre><code>&lt;span style="display: inline; margin: 0; padding: 0;"&gt;New Span&lt;/span&gt;\n</code></pre>\n'}, {'answer_id': 80408, 'author': 'Prestaul', 'author_id': 5628, 'author_profile': 'https://Stackoverflow.com/users/5628', 'pm_score': 2, 'selected': True, 'text': '<p>Simply override any span styles.  Set layout properties back to browser defaults and set formating to inherit from the parent:</p>\n\n<pre><code>span#yourSpan {\n  /* defaults */\n  position: static;\n  display: inline;\n  margin: 0;\n  padding: 0;\n  background: transparent;\n  border: none;\n\n  /* inherit from parent node */\n  font: inherit;\n  color: inherit;\n  text-decoration: inherit;\n  line-height: inherit;\n  letter-spacing: inherit;\n  text-transform: inherit;\n  white-space: inherit;\n  word-spacing: inherit;\n}\n</code></pre>\n\n<p>This should be sufficient, although you may need to add !important if you are not using an id:</p>\n\n<pre><code>&lt;span class="hello-node"&gt;hello&lt;/span&gt;\n\nspan.hello-node {\n  /* defaults */\n  position: static !important;\n  display: inline !important;\n  ...\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/80202', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/15023/']