$('.input-group-addon').click(function(){
$(this).parent() // selects the parent container with the class 'input-group'
.children('input') // selects the input element within the container
.removeAttr('readonly'); // removes the readonly attribute from the input element
});
- By clicking on the icon element, a function is triggered
- We are targeting the parent element of the icon to access the container it belongs to
- Within the container, we locate the input element (there should be only one for semantic purposes)
- The readonly attribute is removed from the input element
Testing this functionality yielded successful results (you cannot edit the telephone number until clicking the red square) https://codepen.io/anon/pen/pXXPNo
Implementing this solution not only helps you progress but also enhances your understanding
If you are dynamically creating elements rather than having them preloaded in the DOM, adjust your event binding as follows:
$('body .input-group-addon').on("click", function(){
$(this).parent() // gets parent container 'input-group'
.children('input') // gets the input in the container
.removeAttr('readonly'); // removes the readonly attr from the input
});