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 th开发者_高级运维e 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.
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.
精彩评论