Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6458 closed bug (duplicate)

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

Change History (6)

comment:1 Changed 13 years ago by rtordable3

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.

comment:2 Changed 12 years ago by Rick Waldron

Owner: set to 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.

comment:3 Changed 12 years ago by Rick Waldron

Keywords: needsreview added

comment:4 in reply to:  2 Changed 12 years ago by [email protected]

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 rwaldron:

Please provide a reduced jsFiddle test case, thanks!

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

comment:5 Changed 12 years ago by dmethvin

Keywords: needsreview removed
Resolution: duplicate
Status: pendingclosed

comment:6 Changed 12 years ago by dmethvin

Duplicate of #6941.

Note: See TracTickets for help on using tickets.