Reputation: 86
im newbie in jquery/javascript and got this code below:
$("#result").empty().html(result);
can someone explain the code. correct me if im wrong but i think, it explains that it should empty first before displaying another result in the id of result?
Thank you.
Upvotes: 0
Views: 274
Reputation: 21
$("#result").empty() will remove everything inside #result. $("#result").html() will retrieve everything inside #result
I think what you need is .text(), .val() or .append()
$("#result").append(result) will populate #result with the data from result, removing what was already inside #result. I don't know if i make myself clear, i'm new here =)
Upvotes: -1
Reputation: 82241
.html()
Set the HTML contents of each element in the set of matched elements. Thus you do not need to explicitly empty it as you are already overwriting the content. You can simply use:
$("#result").html(result);
Upvotes: 2