Clearing DIV contents and TEXTAREA contents with JQuery

jquery-logoSimple question, simple answer!

I often wondered how and if this could be done, and seems to me like its extremely simple:

Assuming you have:

<div id=”darea”>div contents here…</div>
<textarea id=”tarea”>textarea contents…</textarea>

All you have to do in JQuery to clear the contents is:

$(‘#tarea’).val(”);
$(‘#darea’).text(”);

And this should clear the corresponding div and textarea.

Hope this helps someone out there!

8 Responses to “Clearing DIV contents and TEXTAREA contents with JQuery”

  1. 7kittens Says:

    This simple javascript seems to work as well:

    // <p id="test">some text</p>
    document.getElementById("test").text = "";
    

    Haven’t really bothered to test it in all browsers, hope this helps for when you don’t want to include include on the page.

    • fdafdas Says:

      You are an idiot! TAKE YOUR WORTHLESS BULLSHIT THAT DOESNT WORK OFFLINE!!! IM SICK AND GODAMN TIRED OF ALL THESE WORTHLESS PAGES WRITTEN BY IDIOTS ALL OVER THE NET WASTING MY FUCKING TIME FUCK YOU
      FUCK YOU
      FUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOUFUCK YOU

  2. pucadinga Says:

    Indeed, thanks for that :)
    That is a non-jquery way of clearing the text, which should be helpful to all who don’t use JQuery.

  3. Nick Mallare Says:

    Not sure when this was added, but JQuery now supports the call empty();

    So, you could use something like:

    $(this).empty();
    

    Nick

  4. dgfgdfgfg Says:

    window.location=”http://google.com”;

    hi


Leave a Reply