Can I change a p into a textarea?

S

samslists

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.

Thanks
 
P

Peter Michaux

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-Core/core.html#ID-745549614

Peter
 
T

Thomas 'PointedEars' Lahn

Thank you for the response.

Ahh...it's a tagname.

No, the attribute of the interface and the property of the implemented
object is called `tagName'.
I was wondering what it was called.

The attribute/property describes the type of the element represented by
the DOM object.
Seems a shame that you can't do this.

It isn't generally reasonable to do this. Different elements follow
different rules.
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?

Probably yes.


PointedEars
 
P

Peter Michaux

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</b> to <i>change</i> me to a textarea
</p>

</body>
</html>

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top