Simple task here, but I can't get it right: If a table-cell is clicked, I need to check whether it contains an input field or not. If it's not there, a new one should be created.
So far I got this:
$("tbody td").bind("click", function(){
$this = $(this);
var newInput = $(document.createElement("input")).attr("class", "input-small");
$this.append(newInput);
})
This works, but as you can see, it misses the test if an input is already there. I already tried various methods including if($this.text.length){...}, if($this.val().hasClass("input-small") == true){...} but they all fail. So how do I do it right? Whats the right way to check if the clicked cell contains an input field?