I am newb with jQuery and would appreciate your help.
I am struggling a bit with jQuery DOM manipulation, where I have an <input>, and .on("blur") it updates the DOM, by removing the <input>, and inserts a <div> with the <input> value, and when you click on the <div>, it must update the DOM, by adding back the <input> with the value of the <div>.
When I click on the <div>, nothing happens. Any Ideas?
My current code:
$(document).ready(function() {
var inputValueByClassName = null;
$(".divInput").on("click", function() {
alert("clicked!")
$(".divInput").replaceWith($('<input type="text" class="textInput>'));
$(".divInput").html(inputValueByClassName);
});
$(".textInput").on("blur", function() {
inputValueByClassName = $('input[type="text"].textInput').val();
console.log(inputValueByClassName);
$(".textInput").replaceWith($('<div class="divInput">' + inputValueByClassName + '</div>'));
})
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="textInput" value="123"><br>