Get script from a DIV with JS

2

It is possible to get the SCRIPT of some element .. EX:

<div id="form">
    <div class="box">
        <p>Pegar apartir da 'class="box"'</p>
    </div>
</div>

get the complete code inside the id="form" ? What would it be:

<div class="box">
    <p>Pegar apartir da 'class="box"'</p>
</div>
    
asked by anonymous 24.07.2015 / 21:31

2 answers

5

If by "script" you mean to get all the HTML inside the div, do so:

var form = document.getElementById('form');
var conteudo = form.innerHTML;
alert(conteudo);
<div id="form">
    <div class="box">
        <p>Pegar apartir da 'class="box"'</p>
    </div>
</div>
    
    
24.07.2015 / 21:32
0

As the question is in the "jQuery" category I will give the answer in jQuery:

var div_form = $('#form');
var html = div_form.html();

If you do

console.log(html);

You will see the html code extracted from the #form element.

You can use the simplified version:

var html = $('#form').html();
    
24.07.2015 / 21:41