jQuery 事件2-2练习
来源:2-2 编程练习
深海皮皮虾
2019-06-08 16:07:41
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>点击事件</title> <style type="text/css"> div { float: left; margin: 10px; width: 100px; height: 100px; color: #fff; font-size: 50px; text-align: center; line-height: 100px; text-indent: -9999px; background-color: #333; } </style> </head> <body> <h1>添加事件处理</h1> <div>43</div> <div>21</div> <div>56</div> <div>16</div> <div>89</div> <div>94</div> <div>46</div> <div>26</div> <div>67</div> <div>90</div> <div>25</div> <div>10</div> <div>84</div> <div>76</div> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script> <script> $(document).ready(function() { $("div").click(function() { $(this).css({"text-indent": "0"}).siblings("div").css({"text-indent": "-9999"}); }) }) </script> </body> </html>
老师 为什么 siblings() 里面要加入“div” ? 当前点击的<div>的兄弟元素也包括<h1>不是吗?
1回答
同学你好,h1标签也是div标签的兄弟元素,但是练习要求是给div元素添加样式让内容显示出来,所以把h1标签筛选出来了。另 不要忘记加单位哦
如果帮助到了你,欢迎采纳,祝学习愉快~
相似问题