Home > Enterprise >  I want to add a "show password" button with bootstrap 5
I want to add a "show password" button with bootstrap 5

Time:11-24

i want something like this

Image form bootstrap

but i get this instead

Image on my localhost

And this is my code:

              <input
                type="password"
                
                placeholder="contraseña"
                id="password-input"
                aria-label="password input"
                aria-describedby="password-input"
              />
              <span  id="password-input">@</span>

All the examples that i see in internet are the same, looks nice but i put the code in my proyect and don't work :(

CodePudding user response:

Wrap your input and span tag with this way

<div >
    <input type="password"  placeholder="contraseña" id="password-input" aria-label="password input" aria-describedby="password-input" />
    <span  id="password-input">@</span>
</div>

CodePudding user response:

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet"
        href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<style>
    i {
        cursor: pointer;
    }

</style>

<body>
    <div>
        <!-- Password field -->
        <label for="Password">Password:
            <input type="password"  value="" id="myInput">
            <!-- An element to toggle between password visibility -->
            <i  style="font-size:24px" onclick="myFunction()"></i>
        </label>
    </div>

    <script>
        function myFunction() {
            var x = document.getElementById("myInput");
            if (x.type === "password") {
                x.type = "text";
            } else {
                x.type = "password";
            }
        }
    </script>
</body>
  • Related