开发者

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

开发者 https://www.devze.com 2022-12-17 00:43 出处:网络
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 b

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号