Add Style to button

59 views
Skip to first unread message

Abhi120

unread,
May 23, 2012, 4:18:30 AM5/23/12
to Closure Library Discuss
I am trying to implement button dynamically.
Here is my code:
.............
var button = new goog.ui.Button('Hello!');
button.render(goog.dom.getElement('buttonDiv')); // button div in
HTML

button.addClassName('className');
button.setId('idName');

.............
the contents of my css file are:
.............
.className {
background-color:red;
}
#idName {
color:blue;
}
.............
The style corresponding to class is working while the one with id is
not working. Is it that 'setId' used is wrong?
Help!

Andre Tannus

unread,
May 23, 2012, 1:14:58 PM5/23/12
to closure-lib...@googlegroups.com
This ID you're setting is not the HTML id attribute I believe you're thinking about.
It is component's unique identifier!

On a side note, I avoid using the ID attribute for styling elements.
There's nothing inherently wrong with it but HTML IDs *should* be unique in an HTML document, and using it for styling might incline you to reuse that style declaration on a different element.


--
A ciência consiste em perturbar um sistema e analisar sua reação. Eu, sou uma perturbação.

André Tannús | Ideas at Epungo
ata...@epungo.com.br | +55 11 8053-7636 | +55 11 2389-4360 

"Somewhere, something incredible is waiting to be known."
Carl Sagan

Reply all
Reply to author
Forward
0 new messages