appendHTML counter - how to do?

2

I have a label in the form of my site that adds to a div (in the example case, id of this div is grupoExt ) an HTML content. Here is the code:

var numeroFE = 2;
$("#addFE").click(function(){
    var html3  = "<div class='BoxForm1'>";
        html3 += "<div class='inputMGM'><input name='nomeFE"+numeroFE+"' id='' class='validate[required]' title=''></input></div></div>";
        html3 += "<div class='BoxForm2'>";
        html3 += "<div class='inputMGM'><input name='empresaFE"+numeroFE+"' id='' class='validate[required]' title=''></input></div></div>";
    $('#grupoExt').append(html3);
    document.getElementById('grupoExt_text').value=numeroFE;
    numeroFE++;
});

I wonder if it's possible to do otherwise. That is, using JavaScript code to remove this code added to div grupoExt

    
asked by anonymous 20.03.2017 / 18:46

1 answer

7

You can do only:

document.getElementById('grupoExt').innerHTML = '';

What with jQuery would be:

$('#grupoExt').html('');


With jQuery you also have the functions:

remove () :

$('#grupoExt *').remove();

empty () :

$('#grupoExt').empty();

Whose final result of the two above is the same (although different things return).

    
20.03.2017 / 18:49