#2 =))))))))))) #3 I think the difference consists in: - children() finds direct descendants - find() finds ALL the descendants (the children, the children of children, and so on)
#1 maybe you can do it...but I never tried (BUT THERE ARE SOME USEFUL PLUGINS) var e = $("document").append("<fieldset></ fieldset>").children("fieldset").filter(":last"); e.attr({ id: "myid", ... }); I cannot answer your last question, cause I don't know the response =) On Sep 22, 5:25 pm, RichUncleSkeleton <[EMAIL PROTECTED]> wrote: > Cheers for #2, can't believe I didn't think that... > > I've just looked up children() in the jQuery API, but I don't see how > it is different to find(). Unfortunately the jQuery demos are useless > since they don't actually do anything... > > As for #1, I thought one was supposed to add objects to the DOM rather > than strings. Something like: > var elm = createElement('fieldset') > elm.addAttr(...) > elm.addContent(..) > $('fieldset:last').after(elm) > > I thought that is supposedly better than passing a long string which > then gets converted to objects somehow (does jQuery do this, or is it > left up to the browser?) > > Cheers, > Scott. > > On Sep 22, 1:43 pm,muccy<[EMAIL PROTECTED]> wrote: > > > 1) I think it's a good way. $("#some").after("yourhtml"); to insert > > some tags after... > > > 2) you could save "form#question-setup fieldset:last" for example...so > > var f = $("form#question-setup fieldset:last"); > > f.after("...").slideDown("fast").filter("input[type=text]").focus(); > > f.filter("div.question-remove").click(handler); > > > But you know the code, the children, etc... :) > > > 3) I don't know ... I use children() often...but it depends on the > > cases > > > On Sep 22, 1:46 am, scottyreg <[EMAIL PROTECTED]> wrote: > > > > Just started with jQuery, absolutely loving it so far! I just have a > > > few questions about what I have written, and if there are better ways > > > of doing things (it all works perfectly). > > > > I copied the relevant code to a text file, which can be seen > > > athttp://www.doheth.co.uk/files/jqueryhelp.txt > > > It's a fairly simple script for my PHP Contest Scoreboard program that > > > allows the user to add a new "question" to a form. Essentially it just > > > adds a fieldset after the current last one in the form. It also > > > animates the new fieldset into view, focuses the text field inside it > > > and adds a button to remove that fieldset. > > > > My questions are as follows... > > > > 1. In the 'after' function I have a long string of HTML. This seems > > > akin to using innerHTML, which is generally frowned upon. Is there a > > > 'proper' or preferred way to insert HTML in jQuery? > > > > 2. I have a bit of repeated code here, namely the 'form#question-setup > > > fieldset:last' selections. The last three groups are referring to the > > > same fieldset (the newly created one - but this is different from the > > > one referred to in the first half of the script). Is there some > > > shortcut I can apply to save a little time and code? (It's probably > > > negligible, but still...) > > > > 3. If anyone has any other improvement suggestions, I'm all ears ;) > > > > -- > > > Scott.