Patel
Patel

Reputation: 585

changing of text color and image background color using css and javascript

i want to write a script for changing of text color and image color on click .. here i want to call the external style sheets (which i ll be creating) to the function .. each color ll be ve ng differnt .css page. so that when i click the orange color the text and the image background should change to to the orange color if i click to red it should change to red..can anyone pls help me out in dis.. any ideas or sugessions... thanks in advance.

Upvotes: 2

Views: 1168

Answers (1)

Adam Hopkinson
Adam Hopkinson

Reputation: 28795

Define each colour as a class in your CSS:

.red {
color: red;
}

.blue {
color: blue;
}

Then set a click attribute in your HTML:

<p onclick="javascript: this.setAttribute('class', 'red');">Click to make me red</p>
<p onclick="javascript: this.setAttribute('class', 'blue');">Click to make me blue</p>

There are optimisations not described here - using unobtrusive javascript mainly - but this should give you a start.

Upvotes: 3

Related Questions