Skip to main content

Bug Tracker

Side navigation

#1146 closed bug (invalid)

Opened April 26, 2007 01:42PM UTC

Closed April 26, 2007 06:05PM UTC

Wrong dom structure in ajax

Reported by: RSA Owned by:
Priority: major Milestone: 1.1.3
Component: ajax Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:
Description

index.html

<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function update()
{
	$.post('ajax.html', function(html){
		$('#B').html(html);
		alert($('#A').get().parentNode);
	})
}
</script>
<div id="B" onclick="update()">Click to load</div>

ajax.html

<div id="A">Loading completed</div>

The problem is that you can not use parentNode of an element you loaded through AJAX.

Test case also attached to the ticket.

Attachments (1)
  • jquery.zip (18.8 KB) - added by RSA April 26, 2007 01:42PM UTC.

    Test case

Change History (1)

Changed April 26, 2007 06:05PM UTC by brandon comment:1

resolution: → invalid
status: newclosed

Get takes a 0 based number of which element to pull from the jQuery object. Try calling get with 0 to get the first matched element

 $('#A').get(0).parentNode 

You could also use Array notation to get the element like this

 $('#A')[0].parentNode; 

Another solution is to use the parent method (recommended as it normalizes browser differences) on the jQuery object like this

 $('#A').parent();