开发者

jQuery HTML problem

开发者 https://www.devze.com 2023-03-09 09:00 出处:网络
I wrote this: <head> <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js\"></script>

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

精彩评论

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