Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13684 closed bug (notabug)

Create element, wrap it, append to it

Reported by: idiotbarn@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

Hi I stumbled upon this, and thought you might wanted to know... I create an element with jquery. Then I wrap it around an existing DOM element. When trying to append to the created element, it fails unless if I research the DOM

<html>
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

</head>
<body>
	<div id="ss"></div>
	
    <script>
        $(document).ready(function () {
            var elem = $("<div id='wrapper'></div>");
            $("#ss").wrap(elem);

            //elem.append($("<div class='child'></div>")); //do not work
	//$(elem).append($("<div class='child'></div>")); //do not work
	//$("#wrapper").append($("<div class='child'></div>")); //works
        });
    </script>
</body>
</html>

Change History (1)

comment:1 Changed 7 years ago by m_gol

Resolution: notabug
Status: newclosed

See last example on docs: "Notice it doesn't move the object but just clones it to wrap around its target." http://api.jquery.com/wrap/

This is a correct behavior. A test case showing those are different elements: http://jsfiddle.net/m_gol/j5Qpt/

Note: See TracTickets for help on using tickets.