Seppo Kuusela Seppo Kuusela - 1 year ago 108
CSS Question

Jquery remove text/numbers inside of div

i have started learning JQuery and made script that when you press button it adds that button value into a div. I made a CLEAR text that when you press it clears the text / numbers from that div but the problem is when you press the CLEAR and i press button that should add X value into that div it does not print it and i have to refresh the page.






<div id="div_number" class="total"></div>


I also have to remove
from this
Oh it can be my mistake, i also have to remove the value="" from


This is the code that i have made

Answer Source


So, based on your provided code on jsfiddle, you just need to add this: count = 0; after this: $('.total').empty();

$(".clear").click(function() {
    count = 0;

I kept following for future readers

You used remove(), instead of empty() or just text('').

From jQuery documentation:

  • .remove( [selector ] ): Remove the set of matched elements from the DOM.
  • .empty(): Remove all child nodes of the set of matched elements from the DOM.
  • text(): Get the combined text contents of each element in the set of matched elements, including their descendants.

Read more about remove(), empty() also text()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download