<span id="field1" class="update">Sometext goes here</span>
Code language: HTML, XML (xml)
Following CSS also can be applied in order to make the background light yellow. .update {
background-color:#FFFFC6;
display: inline;
}
Code language: CSS (css)
Once this is done, the html screen will look likes: function fnUpdate(value, no) {
alert("Handler function called.")
return true;
}
var updateClick = function(e){
if(typeof this != "object") {
return;
}
e.preventDefault();
e.stopPropagation();
var text = document.createElement("input");
text.setAttribute("type", "text");
text.setAttribute("value", $(this).text());
var button = document.createElement("input")
button.setAttribute("type", "button");
button.setAttribute("value", "Update");
var cancel = document.createElement("A")
cancel.setAttribute("href", "javascript:");
cancel.innerHTML = "Cancel";
var hidden = document.createElement("input");
hidden.setAttribute("type", "hidden");
hidden.setAttribute("value", $(this).text());
$(cancel).click(function(e){
e.stopPropagation();
var val = this.nextSibling.value;
$(this).parent().html(val);
});
$(this).html(text);
$(this).append(button);
$(this).append(cancel);
$(this).append(hidden);
$(text).click(function(e){ e.stopPropagation(); });
$(text).keypress(function(e){
if(e.which == 13) {
$(this).next().click();
}
});
$(button).click(function(e){
e.stopPropagation();
var func = $(this).parent().attr("onupdate");
var id = $(this).parent().attr("id");
var val = this.previousSibling.value;
var fnHandler = func + "(\"" + val + "\"," + id + ")";
this.previousSibling.disabled = true;
this.disabled = true;
var ret = eval(fnHandler);
if(ret == true) {
var val = this.previousSibling.value;
if(val == null || val == "") {
val = " ";
}
$(this).parent().html(val);
}else {
this.disabled = false;
this.previousSibling.disabled = false;
}
});
text.focus();
}
$(document).ready(function() {
$(".update").each(function() {
$(this).click(updateClick);
$(this).attr("title", "Click here to update");
});
});
Code language: JavaScript (javascript)
Thus when this javascript gets loaded, the div or span used to enclosed the text will became an update box which changes into a text box once you click it. Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
First class code! The sample works well (had the change return false to return true at the start of the plugin.)
Hi Viral,
Excellent tutorial. please write some articles on jQuery menu.
when i refresh the page the updated text is not instead of this the "some text to change" appeared
please help
Only wanna tell that this is very useful , Thanks for taking your time to write this. cakebabeabad
hii