[Solved] javascript change div text on ready [closed]


You wrote about IDs, but in your code is class.

<div id=div1>YES</div>
<div id=div2></div>

<script>   
    var div1 = document.getElementById('div1');
    var div2 = document.getElementById('div2');

    if (div1.innerHTML == 'YES') {
        div2.innerHTML = 'You said YES';
    }
</script>

http://jsfiddle.net/7r9cwf3s/

OR generally, if you want to put into the second one div ‘You said ‘ and content of the first div.

<div id=div1>XY</div>
<div id=div2></div>

<script>   
    var div1 = document.getElementById('div1');
    var div2 = document.getElementById('div2');

    div2.innerHTML = 'You said ' + div1.innerHTML; // returns 'You said XY'
</script>

http://jsfiddle.net/7r9cwf3s/1/

6

solved javascript change div text on ready [closed]