php - Jquery .attr() not working to update name of input field -
following html code calling function delete selected image gets store in name property of input tag.
<input id="im1" type="file" name ="upimage1" onchange="readurl(this);" class="upload" required/> <span class="trash-area1" id="im1" onclick="readur(this)"><img class="trash-box" src="img/trash.png" width="24px" height="24px"></span>
following jquery code gets call on onclick function. not letting me make name attribute empty of input tag.
function readur(input) { var id = $(input).attr('id'); var ch = id.substr(id.length - 1); $('.trash-area'+ ch).css('display','none'); $('#'+id).attr('src','img/plus.png'); $('#'+id).attr('name',''); }
you have same id
attribute on elements. rename 1 of them.
here modified code:
<input type="file" name="upimage1" onchange="readurl(this);" class="upload" required/> <span class="trash-area"> <img class="trash-box" src="img/trash.png" width="24px" height="24px"> </span> <script> $('body').on('click', '.trash-area', function () { $(this).prev().attr('name', ''); }) </script>
Comments
Post a Comment