[thelist] Creating DOM element from a string

Matt McKeon matt at camadro.com
Wed Aug 2 19:07:39 CDT 2006

Mohsen Saboorian wrote:
> Hi,
> I have a string (e.g. "<input type='text' value='salam!' />"). Is
> there any way to convert the String into a DOM element and access its
> properties? Or I should use regex for handling such cases.
> A simple solution could be inserting this string into an invisible
> element's innerHTML, and then accessing the DOM object.
> Thanks.

I'm going with your using Javascript so you could do it this way:

var inputElement = document.createElement('input');
inputElement.setAttribute('value', 'salam!');
inputElement.setAttribute('type', 'text');

More information about the thelist mailing list