简体   繁体   中英

wrap() method doesn't seem to work in jQuery

 $('input.text-1').wrap('<span class="textfield-1"></span>'); 
 .textfield-1 { border: 1px solid #d00; display: none; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="text text-1" /> 

Wrap() doesn't seem to work. I don't see <span> s wrapped around input in firebug. If they were wrapped, inputs would be hidden with display: none , but they aren't.

What am I doing wrong here?

Works ok for me. Is it possible that you have a javascript error on the page that is preventing the code from executing?

Here's my test. Element does become invisible and I can see that it is wrapped in the span.

<html>
<head>
<style type="text/css">
.textfield-1 {
    border: 1px solid #d00;
    display: none;
}
</style>
<script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">

    $(function(){
            $('input.text-1').wrap('<span class="textfield-1"></span>');
     });


</script>
</head>
<body>
<input type="text" class="text text-1" />
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM