Page 1 of 1

Change Style with onclick

Posted: Fri Feb 26, 2010 2:37 pm
by easinewe
I am trying to add a style to the page with onclick as shown below.

Code: Select all

 
<a href="#" onclick="document.getElementById('customcontainer').innerHTML='<style type=\'text/css\'> .corporate {filter:alpha(opacity=10); opacity: 0.3;} </style>';return false;">
Change style!
</a>
I can't seem to get it to work. I'm not sure if I'm escaping my quotes for <style type=\'text/css\'> or what.

Is what I'm trying to do even possible? When that line of code is added to the page would the new style be recognized?

Re: Change Style with onclick

Posted: Fri Feb 26, 2010 3:59 pm
by s.dot
style attributes can be set dynamically with javascript:

Code: Select all

onclick="document.getElementById('element').style.bgColor = '#000000';"
For example.

Re: Change Style with onclick

Posted: Thu Aug 05, 2010 12:45 pm
by webadmin40
This one is a great feature but does create a lot of problems in execution. I'm facing almost the same problem. Can any body be of some help. A small piece of working code could do wonders. it would be great if somebody could post the solution on to the thread. I would like to have some insight into this for future use.
Please reply as soon as possible.