Sunday, November 30, 2008

[jQuery] Re: avoid inserting twice

And that can be shortened to:

var h = $('#header');
if (!h.next(':not(#new)').length) {
h.after('<div id="new">test</div>');
}

or, logically, you wouldn't insert two elements with the same ID, so
you could simply use
if (!$('#new').length)

On Nov 29, 4:50 pm, seasoup <seas...@gmail.com> wrote:
> or you can test inside the bind function:
>
> if ($('#header').next().('attr','id') != "new") {
>   $('#header').after('<div id="new">tester</div>');
>
> }
>
> On Nov 29, 7:34 am, Dave Methvin <dave.meth...@gmail.com> wrote:
>
> > Do you only want the button to work once? If that is the case, use .one
> > () instead of .bind().

No comments: