Friday, October 1, 2010

JQuery ajax can't find elements in returned HTML

Programmer Question

I have a simple



$.ajax({
url: someUrl,
method: 'get',
dataType: 'html',
success: function(data) {
$('#someId').append($(data));
}
});


The problem is I can't find elements simply within the returned data. If there's an input with id="myInput" I can't get it with $('#myInput') or $('input[id=myInput]'). I CAN find it with:



$('input').each(function(i,e){ if($(e).attr('id') == 'myInput'){ doStuff(e); } });


But who wants to do that each time? I saw this question but the solutions provided didn't work for me. In addition to what's up there I've tried



$('#someId').html(data);
$(data).appendTo($('#someId'));


and I'm using jQuery 1.4.2. Thoughts, suggestions?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails