Skip to main content

Bug Tracker

Side navigation

#6458 closed bug (duplicate)

Opened April 19, 2010 01:45PM UTC

Closed November 05, 2010 02:10AM UTC

Last modified November 05, 2010 02:10AM UTC

jQuery html(text) parses the javascript code out of its level

Reported by: rtordable3 Owned by: rtordable3
Priority: undecided Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:
Description

$.html(text) parses the text and extracts the child javascripts elements from text and put them at the root level. It doesn't respects de parent/child relationship between the HTML tag elements and the child javascripts. When we iterate with $.each() the resulting elements parsed by $.html() the javascripts elements are in the root level and not in it child level.

Example: I have a parent div with two childs. The first one is a javascript element and the second one is another div with another javascript child.

Here you are the example code:

Example:

var html = $("<div><div id='container1'>" +

"<script type='text/javascript'>" +

"alert('hello world');" +

"</script>" +

"<span>hello world </span>" + "<div id='container1.1'>" +

"<script type='text/javascript'>" +

"alert('hello world 2');" +

"</script>" +

"</div>" +

"</div>" +

"<div id='container2'>" +

"<span>hello world 3</span>" +

"</div></div>");

html.each(function(i){

console.log($(this).html());

});

When we iterate the resulting jQuery object we obtain the following 3 elements:

<div id="container1"><span>hello world </span><div id="container1.1"></div></div><div id="container2"><span>hello world 3</span></div>

alert('hello world');

alert('hello world 2');

The expected result would be like jQuery 1.3.2 only 1 element and with html(), the javascript tags and its content is printed in their corresponding level.

Thanks.

Ramón

Attachments (0)
Change History (6)

Changed April 19, 2010 02:22PM UTC by rtordable3 comment:1

With jQuery 1.3.2 the result is:

<div id="container1"><script type="text/javascript">alert('hello world');</script><span>hello world </span><div id="container1.1"><script type="text/javascript">alert('hello world 2');</script></div></div><div id="container2"><span>hello world 3</span></div>

The HTML code with the javascript.

Changed October 29, 2010 04:54PM UTC by rwaldron comment:2

owner: → rtordable3
priority: → undecided
status: newpending

Please provide a reduced jsFiddle test case, thanks!

Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.

Changed October 29, 2010 05:03PM UTC by rwaldron comment:3

keywords: → needsreview

Changed October 29, 2010 10:47PM UTC by rtordable@yahoo.es comment:4

Here you are the test case:

http://jsfiddle.net/HfcZZ/

Tested with jQuery 0 GIT, 1.4.2 and 1.4.3 versions. It only works with jQuery 1.3.2.

The expected result is one element with its javascripts childs included in their corresponding level.

Thanks.

Rtordable

Replying to [comment:2 rwaldron]:

Please provide a reduced jsFiddle test case, thanks! Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.

Changed November 05, 2010 02:10AM UTC by dmethvin comment:5

keywords: needsreview
resolution: → duplicate
status: pendingclosed

Changed November 05, 2010 02:10AM UTC by dmethvin comment:6

Duplicate of #6941.