Reputation: 61
I am trying to change element with following id into text area.
I don't know js very well so the problem may be really stupid right here.
It doesn't actually change anything right now. The id in variable is correct.
Any ideas please ?
<script>
function editComment(id){
var thisId = "#" + id;
$(thisId).html("<textarea></textarea>");
}
</script>
Upvotes: 0
Views: 31
Reputation: 78535
html
only sets the inner HTML content of the matched elements. You should use replaceWith instead:
$("button").click(function() {
editComment("comment1");
});
function editComment(id){
var thisId = "#" + id;
$(thisId).replaceWith("<textarea></textarea>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="comment1">Comment</div>
<button>Edit</button>
Upvotes: 5