I have a form element that needs to be deleted when a button next to the element is clicked.
$('#btnDel').click(function() {
var num = $('#input').prevAll().size();
$('#form div:nth-child('+ num +')').remove();
}
Can't seem to get that working! Any help very much appreciated. I think I'm just confused with selecting the right element...
EDIT: with markup as requested:
<div id="form">
<form name="create" method="post" action="create.php">
<input type="hidden" id="id" value="1">
<label for="title">Title</label>
<input name="myusername" type="text" id="myusername"><br /><br />
<div id="input" class="clonedInput">
Question: <input type="text" name="question" id="question" />
<input type="button" id="btnDel" value="Remove question" />
</div>
<div>
<input type="button" id="btnAdd" value="Add another question" />
</div>
<input type="submit" name="submit" value="Create survey">
</form>
</div>