-
-
Save florian25686/090cd549070000d6e2eed88943869a93 to your computer and use it in GitHub Desktop.
JQuery replace <p> with a input-Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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