Skip to content

Instantly share code, notes, and snippets.

@florian25686
Created February 27, 2017 14:32
Show Gist options
  • Save florian25686/090cd549070000d6e2eed88943869a93 to your computer and use it in GitHub Desktop.
Save florian25686/090cd549070000d6e2eed88943869a93 to your computer and use it in GitHub Desktop.
JQuery replace <p> with a input-Field
<!DOCTYPE html>
<html>
<head>
<title>Jquery Test</title>
<script src="jquery-3.1.1.js"></script>
<script>
$(document).ready(function() {
$("#changes_tests p").on(
"click",
function( eventObject ) {
var input = $( "<input type=\"text\" id='clicked' value=\"asdf\"></input>").insertAfter( this );
var button = $( "<input type=\"submit\" id='clicked' value=\"Speichern\"></input>").insertAfter( input );
$(button).click(function(){
var submitField = $( "#clicked" ).val();
alert("button clicked: "+submitField);
})
$( this ).detach();
}
)
});
</script>
</head>
<body>
<h1>Testseite</h1>
<p id="clicker 1">lore ipsum</p>
<p id="clicker 2">ipsum lore</p>
<input type="text"></input>
<div id="changes_tests">
<h3>my clicks</h3>
<p id="change1">klick mich</p>
<p id="change2">nicht klicken</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment