Bug Tracker

Modify

Ticket #6458 (closed bug: duplicate)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 4 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 follow-up: ↓ 4 Changed 3 years ago by rwaldron

  • Owner set to rtordable3
  • Priority set to undecided
  • Status changed from new to 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 3 years ago by rwaldron

  • Keywords needsreview added

comment:4 in reply to: ↑ 2 Changed 3 years ago by rtordable@…

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 3 years ago by dmethvin

  • Keywords needsreview removed
  • Status changed from pending to closed
  • Resolution set to duplicate

comment:6 Changed 3 years ago by dmethvin

Duplicate of #6941.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.