Bug Tracker

Modify

Ticket #5954 (closed bug: duplicate)

Opened 3 years ago

Last modified 14 months ago

jQuery(html) create child script elements at root level

Reported by: rtordable2 Owned by:
Priority: major Milestone: 1.4.2
Component: core Version: 1.4.1
Keywords: jQuery(html) each Cc:
Blocking: Blocked by:

Description

jQuery(html) extract child script elements from html and put them in the root level. It doesn't respects de parent/child relationship and when I print out

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());

});

I 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');

With jQuery 1.3.2 we obtain only 1 element and with html(), the script tags and its content is printed in their corresponding level.

Thanks.

Ramón

Change History

comment:1 Changed 3 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 3 years ago by dmethvin

  • Component changed from unfiled to core

comment:3 Changed 3 years ago by addyosmani

  • Owner set to rtordable2
  • Status changed from new to pending

Please resubmit your test case on jsFiddle as there are a number of string literal issues with the code you have posted.

comment:4 Changed 3 years ago by anonymous

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

comment:5 Changed 2 years ago by jitter

  • Owner rtordable2 deleted
  • Status changed from pending to new

comment:6 Changed 2 years ago by snover

  • Status changed from new to closed
  • Resolution set to duplicate

comment:7 Changed 2 years ago by snover

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.