简体   繁体   English

div中的内容未显示

[英]Content inside div not showing

I have this hidden div and when i click a button it shows right but when i try to put a <p> inside the div it wont show, only if I take out <p> everything is good but i only want to put style to the paragraph like <br> and other stuff to make it look better. 我有这个隐藏的div,当我单击一个按钮时,它显示正确,但是当我尝试在div内放置<p> ,它不会显示,只有当我拿出<p>一切都很好,但我只想将样式设置为像<br>这样的段落和其他东西可以使它看起来更好。 please take a look at this JSFiddle 请看看这个JSFiddle

html HTML

<section> <a rel="external" href="#button" id="button" class="button">&#xF011; </a> <span></span> </section>

jquery jQuery的

$(document).ready(function(){
$('#button').click(function(){
$(this).toggleClass('on');
$('p').toggleClass('hidn');
    $('div[id=container]').toggleClass('container');
    $('p[id=p1]').toggleClass('p1');
});
});

You're toggling the class hidn on all the paragraph tags, including the ones inside your div. 您要在所有段落标记(包括div内的标记)上切换hidn类。 But since the ones in the div don't have the class, it's getting added on, making them invisible. 但是由于div中的类没有该类,因此将其添加进来,使它们不可见。

Edit: So either make that paragraph toggle more targeted, or set a rule to make pargraphs with the hidn class in your content div not be invisible. 编辑:因此,要么使该段落切换为更具针对性,要么设置规则以使内容div中具有hidn类的图不可见。

Add the 'hidn' class to the problematic paragraph since you're toggling it as well due to bad jQuery selectors. 将“ hidn”类添加到有问题的段落中,因为由于错误的jQuery选择器,您也要对其进行切换。

http://jsfiddle.net/baJme/4/ http://jsfiddle.net/baJme/4/

<p id="p1" class="p1 hidn">

However, I'd strongly suggest rewriting the code with proper selectors. 但是,我强烈建议您使用适当的选择器重写代码。 Also, follow Arun's advice from the comments about selecting ids. 另外,请遵循有关选择ID的评论中Arun的建议。

You're toggling the class hidn on all the paragraph tags, Instead add an unique id to specific <p> tag.Try this: 您要在所有段落标签上切换hidn类,而是向特定的<p>标签添加唯一的id尝试以下操作:

Html: HTML:

<p id="p0" class="hidn" style="font-size: 50px;font-family: Razer Header Regular;
top: 20%; color: rgb(192,192,192); position: relative; text-align: center;">

Jquery: jQuery的:

$(document).ready(function(){
$('#button').click(function(){
    $(this).toggleClass('on');
    $('#p0').toggleClass('hidn');
    $('#container').toggleClass('container');
    $('#p1').toggleClass('p1');
});
});

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM