单击div后,通过jquery更改css [英] Change css through jquery after a click on a div
本文介绍了单击div后,通过jquery更改css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码不起作用,这段代码有什么问题吗?当我点击div.first时,它必须显示div.second,再次点击才能使其不显示。
Html
< div class =first>一些文字< / div>
< div class =second>一堆文字< / div>
.second {display = none;}
Jquery
$('。first')。click(function(){
$('。second')。css('display','block ');
});
预先致谢
解决方案使用
$。toggle()
切换显示
.second {display = none ;}
< script src =https:// ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script><div class =first>一些文字< / div>< div class = second>一批文字< / div>
The below code isn't working, Is there anything wrong in this code, when I click on div.first it has to show div.second and a click again should make it display none.
Html
<div class="first">some text</div>
<div class ="second">bunch of text</div>
Css
.second{display=none;}
Jquery
$('.first').click(function() {
$('.second').css('display', 'block');
});
Thanks in advance
解决方案
Use $.toggle()
to toggle display
$('.first').click(function() {
$('.second').toggle();
});
.second{display=none;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="first">some text</div>
<div class ="second">bunch of text</div>
这篇关于单击div后,通过jquery更改css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文