-1

I'm trying to catch a div text content and put on another with javascript using innerHTML

usually it works but what happens is that the inseriro text in the new DIV does not get the CSS

I'll try to explain better

I have a div in my wordpress site with the wp_iso_block ID

and I have a div in my HTML footer with iso-block id

I'm doing as follows

document.getElementById ( 'iso-block') innerHTML = document.getElementById ('wp_iso_block') innerHTML..;

so I type in a post wordpress updated text footer in my HTML

It works normally but does not receive the CSS attributes that were given to the div id iso-block appears only text

here it is the best source explained.

My Javascript in HTML

    document.getElementById('iso-block').innerHTML  =   document.getElementById('wp-iso-block').innerHTML;

My HTML in Wordpress post

<div id="wp-iso-block">

ISO 9001:2008 <span>certified company</span>

</div>
Weverton Souza
  • 391
  • 3
  • 14
  • You don't have an element with the id of iso-block –  May 29 '16 at 22:05
  • enclose the iso-block div in another div, and call that div content instead – Nabeel Khan May 29 '16 at 22:16
  • @Bakitai - Yes I have the iso-block element is in my HTML I did not put it in the example not to pollute my question, My div iso-block has a CSS own applying size for text, and color and other attributes but the text coming from innerHTML does not receive these attributes If I do it that way document.getElementById ( 'iso-block') innerHTML = "Text Example."; works it receives CSS attributes But that way document.getElementById ( 'iso-block') innerHTML = document.getElementById ( 'wp-iso-block') innerHTML; It appears only the text and does not receive the attributes. – Weverton Souza May 29 '16 at 22:27
  • @Nabeel Khan - I did it but does not work well :( – Weverton Souza May 29 '16 at 22:28
  • It sounds like it is a CSS/HTML problem rather than a Javascript problem. Maybe you have rules overwriting span tag formatting? When applied in isolation your method works. https://jsfiddle.net/8qpbdm6q/ – Michal May 30 '16 at 00:03
  • show your complete code – Nabeel Khan May 30 '16 at 10:18

1 Answers1

0

I solved my problem by changing my code for that

<script type="text/javascript">

var wp_iso_block = $('# wp-iso-block').text();

$('#iso-block').text(wp_iso_block);

</script>

and using jquery, thank you all.

Weverton Souza
  • 391
  • 3
  • 14