简体   繁体   English

jQuery追加,包装,在元素之前

[英]jQuery Appending, Wrapping, Prepending to element

I am creating a little function that will display a notice when a certain condition is met, so if the condition returns true, it appends a div element with a notice to elements with a set class, however, is not working properly in chrome, it only appends the notices as long as there are less than 3 elements. 我正在创建一个小函数,该函数将在满足特定条件时显示通知,因此,如果条件返回true,它会将带有通知的div元素追加到具有set类的元素上,但是在chrome中无法正常工作,仅在少于3个元素的情况下附加通知。 I tested it in Mozilla and Opera and works well. 我在Mozilla和Opera中对其进行了测试,并且效果很好。

something like the following; 类似以下内容;

if (jQuery('.notice iframe:hidden').length) {
jQuery('.notice').append('<div class="message">Hello World</div>');
};

page HTML sample 页面HTML示例

<div class="notice"><iframe>content</iframe></div>
<div class="notice"><iframe>content</iframe></div>
<div class="notice"><iframe>content</iframe></div>
<div class="notice"><iframe>content</iframe></div>
<div class="notice"><iframe>content</iframe></div>

What the jQuery code does is check if the iframe element is hidden, if it is then it appends the div with hello world message to each element that has the class "notice". jQuery代码的作用是检查iframe元素是否被隐藏,如果隐藏,则将div和hello world消息追加到具有“ notice”类的每个元素上。

Now the issue here is that it doesnt work properly in Chrome, it only works as long as there are only 3 elements only. 现在的问题是,它在Chrome中无法正常运行,仅在只有3个元素的情况下才起作用。

i think u didnt close ur if statmemnt properly thats why.. your code should be like this 我认为如果statmemnt正确,您就不会关闭您,这就是为什么..您的代码应该像这样

if (jQuery('.notice iframe:hidden').length > 0) {
jQuery('.notice').append('<div class="message">Hello World</div>');
};

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

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