Skip to main content

Bug Tracker

Side navigation

#6475 closed bug (invalid)

Opened April 23, 2010 09:48AM UTC

Closed April 24, 2010 12:31AM UTC

Last modified November 18, 2010 10:29AM UTC

jQuery adds new HTML tags when calling manipulation methods

Reported by: danielfranz Owned by:
Priority: undecided Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: Manipulation HTML xmlns Cc:
Blocked by: Blocking:
Description

Not sure if this should be considered a bug.

It happens i.e. in Moz Firefox 3.6.3 (WIN) with the following doctype def:

<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "http:www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:meebo="http://www.meebo.com/">

Example:

I have this code:

<a id="anchor">

<div>

<p>Text</p>

</div>

</a>

I do this:

<script>

$('#anchor').attr('href','test.php');

</script>

Then I end up with this:

<a href="test.php" id="anchor">

<div>

<p>

<a xmlns="http://www.w3.org/1999/xhtml">Text</a>

</p>

</div>

</a>

Question:

Is it necessary for jQuery to add the extra <a> tag between the <div> and the <p>? I know that nesting all that stuff in the outer <a/> is not really lean in the first place but browsers have no problems interpreting it right. So if the extra <a/> is not really mandatory for some future strict xmlns I would generally prefer to keep the code like it is. Limiting methods like attr() or html() to execute what they are asked to.

Thanks guys, you re doing a great job there.

Attachments (0)
Change History (2)

Changed April 24, 2010 12:31AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

Can you reopen this with a complete test case? Please run the document through the XHTML validator, and check in Firebug that the markup is as you expect before using jQuery to set the attribute.

Changed November 18, 2010 10:29AM UTC by jitter comment:2

priority: → undecided

Doesn't happen for me test case