[Javascript] cant create a button with a label

Andrew Clover and-babble at doxdesk.com
Tue Mar 29 08:36:35 CST 2005


judah <judah at drumbeatinsight.com> wrote:

> I can't create a button with a label. What am I doing wrong?

With the <button> element, the button text is the content of the element 
itself, not an attribute - it's <button>Action!</button>, not <button 
value="Action!"/> like with the <input type="button"> element.

For this reason, the contents of a button are accessed through the 
standard DOM Level 1 Core interfaces that all elements have, and not 
through a special property reflecting an attribute. eg.:

function createButton(name, value) {
   var button= document.createElement('button');
   button.type= 'button';
   button.name= name;
   button.appendChild(document.createTextNode(value));
}

The reason for this is to allow images and other markup inside the 
button rather than just plain text.

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Javascript mailing list