I have two elements which are nested and I want to make two click functions. My body tag is for a complete page and I have a button tag which is inside the body tag.
When the user clicks the button I want to add text in my input textbox. When the user clicks outside of the button, which is inside body tag I have to remove text from the textbox.
$(document).ready(function() {
$("button").click(function() {
alert("only button is clicked");
$("input:text").val("Test");
});
$("body").click(function() {
alert("body clicked");
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="setName" value="" /><br/><br/><br/>
<button>Set the value of the input field</button>