Change Style with onclick

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
easinewe
Forum Newbie
Posts: 23
Joined: Mon Jan 11, 2010 3:22 pm

Change Style with onclick

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Change Style with onclick

Post by s.dot »

style attributes can be set dynamically with javascript:

Code: Select all

onclick="document.getElementById('element').style.bgColor = '#000000';"
For example.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
webadmin40
Forum Newbie
Posts: 5
Joined: Wed Jul 21, 2010 4:07 am

Re: Change Style with onclick

Post 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.
Post Reply