# Help with Jquery: $(this).children('.someClass').remove();

**URL:** <https://forum.kirupa.com/t/help-with-jquery-this-children-someclass-remove/329210>\
**Category:** web dev\
**Created:** [August 1, 2012, 7:40pm UTC](https://forum.kirupa.com/t/help-with-jquery-this-children-someclass-remove/329210 "2012-08-01T19:40:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blood\_dew](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@Blood\_dew](https://forum.kirupa.com/u/Blood_dew)\
**Post date:** [August 1, 2012, 7:40pm UTC](https://forum.kirupa.com/t/help-with-jquery-this-children-someclass-remove/329210/1 "2012-08-01T19:40:31Z")

</div>

Here is my function

```auto

(function($) {
  $.fn.extend({
    jqErrorText : function(text) {
    
      if ($(this).children('.errortext').length == 0){
        var span = $('<span />', {
          "class": "errortext"
        }).html(text);
        
        this.append(span);
        this.children().keyup(function(){

          $(this).children('.errortext').remove(); // this is not working and I don't know why!
          
          $(this).removeClass('error');
        });
      }
    }
    });
})(jQuery);

```

The code will work entirely except that I cannot seem to remove the span element that I have created. What I find most confusing is that if I replace $(this).children(’.errortext’).remove(); with just $(’.errortext’).remove() it works. The problem of course is that if multiple fields on my form have an error, then they all are removed. Yet the other usage of $(this).removeClass(‘error’) works just perfectly. Why can’t I reference the child of $(this) and do a remove() to it?

Thanks!
