Executing JavaScript after wrap method

Executing JavaScript after wrap method

Hello.

I just have a problem with the wrap method of jQuery. Look at this markup:

<div id="mainDiv">
    <div id="innerDiv">
           
    </div>
    <script type="text/javascript">
        $(document).ready(function() {
            alert('test');
        });
    </script>
</div>
   
<span onclick="$('#mainDiv').wrap('<div />');">say test</span>

When I insert it on my page I had very interesting results. It says 'test' when page is loaded and it is fine. Click on 'say test' span and you'll see 'test' once more! I don't understand why it is happened, it didn't reload page. More of that if you'll click on the span again you'll not see this word. But wrap works fine I can see additional DIV in DOM model, after each clcik.

I found workaround here: http://forum.jquery.com/topic/wrap-executing-javascripts-again . Just remove script tag after first execution, but looks like a bug.