#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
comment:2 follow-up: 4 Changed 12 years ago by
Owner: | set to rtordable3 |
---|---|
Priority: | → undecided |
Status: | new → pending |
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
Keywords: | needsreview added |
---|
comment:4 Changed 12 years ago by
Here you are the test case:
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
Keywords: | needsreview removed |
---|---|
Resolution: | → duplicate |
Status: | pending → closed |
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.