David Garcia
David Garcia

Reputation: 2696

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. I tested it in Mozilla and Opera and works well.

something like the following;

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

page HTML sample

<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".

Now the issue here is that it doesnt work properly in Chrome, it only works as long as there are only 3 elements only.

Upvotes: 0

Views: 129

Answers (1)

Arda
Arda

Reputation: 470

i think u didnt close ur if statmemnt properly thats why.. your code should be like this

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

Upvotes: 1

Related Questions