I have been looking on Google and StackOverflow but haven\'t been able to find what I\'m after as of yet. If someone could point me in the right direction that would be grea
One possible way:
$('td:contains("(Notes Text)")').click(
function() {
var text = $(this).text();
$(this).text('');
$('').appendTo($(this)).val(text).select().blur(
function() {
var newText = $(this).val();
$(this).parent().text(newText).find('textarea').remove();
});
});
123456
Address 1
10th Feb 2011 (10:43am)
- Awaiting Reply
- Direct
(Notes Text)
1
While the above works, I'd heartily recommend applying a class to the td element that you'd like to be able to edit (assuming you want to be able to edit more than one cell).
Failing that: you could just use the contentEditable attribute in the html:
Edited in response to question from OP (in comments):
One tiny (I hope) other question was, is there any way to move it from being a
textareato andinput?
Yep; that's pretty easily accomplished:
$('td:contains("(Notes Text)")').click(
function() {
var text = $(this).text();
$(this).text('');
$('').appendTo($(this)).val(text).select().blur(
function() {
var newText = $(this).val();
$(this).parent().text(newText), find('input:text').remove();
});
});
123456
Address 1
10th Feb 2011 (10:43am)
- Awaiting Reply
- Direct
(Notes Text)
1
Note the change from $('') to $('') although the type attribute may not be strictly required (since input elements default to type="text" anyway). Also the find('input:text').
References: