javascriptjquery

Can I clean up this jQuery?


I have the following:

$('#EID').empty();
$('#EID').html(data);

Is it possible to simplify this with jQuery and do I really need the empty of the first line?


Solution

  • You don't need the empty no. Just the last line will do the trick.

     $('#EID').html(data);
    

    If both lines are required for any reason, you could still simplify the code like this:

    $('#EID')
      .empty()
      .html(data);