Question: I'm trying to check if an element contains an input element in the following function

```
 $(document).on("click", ".edit_text", function() {
    if($(this).children().is("input")) {
      $(this).html("<input type='text'>")
    }
 })

```

I can't figure a way of doing this as all the solutions point to using the selector such as `$(".edit_text :contains(input)")`

I need to use `$(this)` as I am using the function on elements that have a class and not on a specific element.

Is there any way of achieving this?

Answer: 
Try [`:has()`](https://api.jquery.com/has-selector/) as in:

```
if($(':has("input")', this)) {

```

As the docs for `:has()` state:

> 
> Selects elements which contain at least one element that matches the
>  specified selector.
> 
> 
> 

`:has()` searches all descendants, not just children. Or you could use [`.has()`](https://api.jquery.com/has/) like:

```
if($(this).has("input")) {

```

Usually `.has()` performs better than `:has()`
This isn't totally clear what you're doing, but the modifications to your code below should get you going in the right direction:

```
$(document).on("click", ".edit_text", function() {
    // search for an 'input' element within the context of the clicked element
    // .length will be > 0 if any are found
    if( $('input', this).length ) {
      $(this).html("<input type='text'>")
    }
});

```