Question: Using Jquery im trying to place input text box over label when i click on edit button and when i click on cancel button im changing it from input to label

MyCode

```
<label id="labelId" class="labelclass">label</label>
<input value="input" type="text" class="inputclass" id="inputId" style="display:none;"/>
<button id="edit">edit</button>
<button id="cancel">cancel</button>

<script type="text/javascript">
    $(document).click(function(){
        $('#edit').addClass('inputclass').removeClass('labelclass');
        $('#cancel').addClass('labelclass').removeClass('inputclass');
    });
</script>

```

Any Help is Appreciated Thanks!

Answer: 
You are binding your function to any click on the document, specify the element and what you want to happen after clicking each one, like so:
...Edit:
Here is a solution with replaceWith() - using an input and a label element and hide/showing them would work as well, this would "change" the element itself:

```
<label id="theField" class="labelclass">label</label>
<button id="edit">edit</button>
<button id="cancel">cancel</button>

$(document).ready(function(){
    $('#edit').click(function(){
        $('#theField').replaceWith('<label id="theField" class="labelclass">label</label>');
    });
    $('#cancel').click(function(){
        $('#theField').replaceWith('<input value="input" type="text" class="inputclass" id="theField" "/>');
    });

});

```
You could use following logic to make your code more user freindly imho:

```js
$(document).ready(function() {
  $('#edit, #cancel').click(function() {
    $('#edit, #cancel').prop('disabled', function(){return !this.disabled});
    $(this).siblings('.labelclass, .inputclass').toggle();
  });
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="labelId" class="labelclass">label</label>
<input value="input" type="text" class="inputclass" id="inputId" style="display:none;" />
<br/>
<button id="edit">edit</button>
<button id="cancel" disabled>cancel</button>
```