开发者

jQuery HTML problem

I wrote this:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script>
        $("div.productInfo").wrap("<div id='productDetails'></div>");
    </开发者_如何学运维script>
</head>

<body>
     <div class="productInfo">Whatever.</div>
</body>

And it didn't work?. Thanks.


your element hasn't been rendered when your script runs... try this:

<script>
    $(document).ready(function(){
        $("div.productInfo").wrap("<div id='productDetails' />");
    });
</script>


Looks like you've left out document.ready:

<script>
    $(document).ready(function(){
        $("div.productInfo").wrap("<div id='productDetails' />");
    });
</script>


Place the SCRIPT elements at the bottom of the page and use a ready handler:

<!DOCTYPE html>

<html>
<head>
    <title>A valid page</title>
</head>
<body>
<div class="productInfo">Whatever.</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
    $(function() {
        $('div.productInfo').wrap('<div id="productDetails"></div>');
    });
</script>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜