That's the part that had me a little confused, that it's showing up at all; as far as I can tell, the way .append() is used is correct. A page, like Mike said, that shows what you're using and the context in which you're using it would definitely go a long way towards figuring this out.
- T.J. On Dec 14, 4:17 pm, Michael Geary <m...@mg.to> wrote: > Oh, wait a minute. You said the content *does* show up in the div. > > I think you need to post a link to a test page, so we can see what is > actually happening. That would make it a lot easier to help troubleshoot. > > -Mike > > > > On Mon, Dec 14, 2009 at 2:15 PM, Michael Geary <m...@mg.to> wrote: > > T.J., I think you're right on the money. > > > Joseph, no need to wonder whether you've run into an issue with the > > .append() method. Instead, verify whether you actually have the right data > > on hand or not. > > > Where you had this code: > > > $('#somediv').append(html); > > > Change it to: > > > alert( html ); > > > and see what the alert shows. > > > It may well say something like "undefined". If you try T.J.'s suggestion, > > you may find something more useful. Either way, by alerting the value (or > > using console.log with Firebug or the like), you can check that the HTML > > code you're trying to append is actually what you want. > > > -Mike > > > On Mon, Dec 14, 2009 at 2:03 PM, T.J. Simmons > > <theimmortal...@gmail.com>wrote: > > >> Have you tried it without the data.content? > > >> IE: var html = data; > > >> that should get you all of the HTML you're pulling in via AJAX. I > >> haven't ever seen the .content method before, and a quick Google > >> search came up with nothing for it.. maybe that's the problem? I'm > >> sure someone who knows more will come in and blast my answer, but > >> that's my thought. > > >> Hope that helps. > > >> - T.J. > > >> On Dec 14, 10:05 am, joseph7 <radioak...@gmail.com> wrote: > >> > Hi, > > >> > So, I'm attempting to add HTML to a document via Ajax, but when I get > >> > back the content, I'm finding that no matter what I try, I can't get > >> > it added to the DOM correctly. Basically I'm doing this: > > >> > $.post('ajax.php', > >> > function (data) { > >> > var html = data.content; > >> > $('#somediv').append(html); > >> > } > >> > ); > > >> > The HTML I'm loading looks like this: > > >> > <div class="somediv"> > >> > <form id="someform"> > >> > <p class="someclass">Name:</p> > >> > <input style="display: none;" type="textbox" > >> name="somefield" > >> > value="test" /> > >> > </p> > >> > </form> > >> > </div> > > >> > While the content does show up in the div, if I try to get the form by > >> > doing $('#someform'), jQuery returns nothing. I've tried using .append > >> > () and .html(), and neither way gives me what I want. Is there > >> > something I'm missing here? I know adding objects to the DOM in jQuery > >> > is ridiculously easy, so I feel like I'm either running up against > >> > something impossible, or I have a hugely flawed concept of how append > >> > () and html() work.