根据其他div的背景颜色更改div的背景颜色 [英] Changing background color of a div based on background color of some other div

查看:108
本文介绍了根据其他div的背景颜色更改div的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JQuery中使用"MyNumbers"类的div更改"MyBullets"类的div的颜色?

How to change the color of div with "MyBullets" class with the color in a div with "MyNumbers" Class in JQuery?

类似的东西.

$MyComponent.find(".MyBullets").css("background-color",$thisComp.find(".MyNumbers").css(background-color)....);

推荐答案

尝试一下,

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

 </script>
  <script>
    function changeColor() {

        var color = $(".MyNumbers").css("background-color");
        $(".MyBullets").css("background-color", color);
    }



</script>

</head>
<body>

<div class="MyBullets">MyBullets</div>
<div class="MyNumbers" style="background-color:Red";>MyNumbers</div>
<input type="button" value="click here to change color" onclick="changeColor()" />
</html>

这篇关于根据其他div的背景颜色更改div的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆