On May 29, 10:43 pm, "samsli...@gmail.com" <samsli...@gmail.com>
wrote:
On May 29, 9:10 pm, Peter Michaux <petermich...@gmail.comwrote:
On May 29, 8:36 pm, "samsli...@gmail.com" <samsli...@gmail.comwrote:
Hi...
I've seen code which changes a paragraph into a textarea (to allow it
to be edited)...by creating a brand new text area, inserting that into
the dom at the right place, and deleting the paragraph from the dom.
I.e.http://www.quirksmode.org/dom/cms.html
What I'm wondering is: is there some way to simplify this? Can I
just tell the paragraph to become a textarea?
I'm pretty sure the answer is no...but I want to make sure there is no
way.
I believe the answer is no. The tagName attribute is readonly
http://www.w3.org/TR/DOM-Level-2-Cor...l#ID-745549614
Peter
Thank you for the response.
Ahh...it's a tagname. I was wondering what it was called. Seems a
shame that you can't do this.
Is there a library that creates a new element and deletes the old
element as if you had just changed the tagname? So I can get the same
behavior transparently?
You could write your own. Here is an incomplete starter example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Page Title</title>
<script type="text/javascript">
function change(el) {
var ta = document.createElement('textarea');
ta.rows = '10';
ta.cols = '70';
ta.innerHTML = el.innerHTML;
el.parentNode.replaceChild(ta, el);
}
</script>
</head>
<body>
<p onclick="change(this);">
click <b>me</bto <i>change</ime to a textarea
</p>
</body>
</html>
Peter