Contrary to appendHTML - how to do?

Asked

Viewed 271 times

2

I have a label in the form of my website adding to a div (in the case of the example, the id of that 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 is possible to do otherwise. That is, use Javascript code to remove this code added to div grupoExt

1 answer

7


You can do it alone:

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

That with jQuery it 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).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.