Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JQuery wrapping doesn't work correctly.

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
0
0
US
I am trying to wrap an input statement with a div and then wrap both of those with another div.

I am than trying to add some span code after the input.

All of this works fine separately but not together.

Code:
<!DOCTYPE html>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
    <title></title>
    <script src="Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.11.2.js" type="text/javascript"></script>
    <script type="text/javascript">
    var PopupOn = "";

    $(document).ready(function () {
        $("input[name*='UserName']").wrap("<div class='input-group usergroup1'/>");
        //$("input[name*='UserName'], .usergroup1").wrapAll("<div class='form-group'/>");
        //$("input[name*='UserName']").after("<span class='input-group-addon'><i class='glyphicon glyphicon-user'></i></span>");
    })
    </script>
</head>
<body>
    <input class="form-control input-sm" id="UserName" name="UserName" type="text" value="" />
</body>
</html>

If I run this as written with the wrapAll and Span code commented out, the first div wraps the input statement correctly.

If I uncomment the 2nd line (wrapAll), the first line doesn't wrap the right way. It doesn't wrap the input statement. but the wrapAll statement did wrap both correctly.

I end up with:

Code:
...
<div class='form-group'>
   <div class='input-group usergroup1'><div>
   <input...></input>
</div>
...

instead of:

Code:
...
<div class='form-group'>
   <div class='input-group usergroup1'>
      <input...></input>
   <div>
</div>
...

The span does work correctly but the 1st wrap is still wrong.

Why is that?

Thanks,

Tom
 
forum216

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top