我想通过单击链接来更改页面的CSS [英] I want to change the css of a page on a the click of a link

查看:69
本文介绍了我想通过单击链接来更改页面的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我如何做到这一点,如果有人点击一个网站图标页面的颜色将改变
网站:ibrepository.com 您可以使用 .css() jQuery的功能。



 

<!DOCTYPE html>< html>< head> < script src =https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js>< / script>< / head>< body> < a href =#id =myAnchor>点击此处< / a> < div id =someDiv> Hello World< / div>< / body>< / html>

在此工作DEMO


So I want to make different versions of my website (color wise) with only html and css if possible.

How do I make it so if someone clicks an icon the color of the page will change Website: ibrepository.com

解决方案

You can do so by using .css() function of jQuery.

$(function() {

  $("#myAnchor").click(function() {
    $("#someDiv").css("color", "yellow");
  });

});

<!DOCTYPE html>
<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>

  <a href="#" id="myAnchor">Click here </a>

  <div id="someDiv">
    Hello World
  </div>

</body>

</html>

Working DEMO here

这篇关于我想通过单击链接来更改页面的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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