Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- Sample Type Ahead Search Project - full project coming soon -->

<!-- Thanks to Wes Bos for the inspiration and collegefootballdata.com for the API -->

<div class="main">
  <h1>Start Typing a Player Name to Search</h1>
  <form action="">
    <input type="text" placeholder="Player Name">
    <ul class="results"></ul>
  </form>
</div>
              
            
!

CSS

              
                * {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .main {
            max-width: 400px;
            margin: 50px auto;
        }

        h1 {
            color: #222;
            font-weight: 400;
            letter-spacing: .2px;
            font-size: 18px;
        }

        input {
            box-sizing: border-box;
            padding: 20px;
            font-size: 30px;
            width: 100%;
            box-shadow: 0 0px 5px rgba(30, 30, 30, 0.2);
            position: relative;
            z-index: 2;
        }

        input:focus {
            border-color: rgba(30, 30, 30, 1);
            box-shadow: 0 0px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(30, 30, 30, 0.6);
            outline: 0 none;
        }

        .results {
            width: 100%;
            position: relative;
            z-index: 1;
            bottom: 25px;
            box-shadow: 0px 5px 5px rgba(30, 30, 30, 0.2);
            border-radius: 4px;
            padding: 10px 0 0;
            max-height: 300px;
            overflow: scroll;
        }

        .results li {
            padding: 10px;
            list-style: none;
            position: relative;
            /* give each individual result a button style */
            border: 1px solid #ddd;
            margin: 3px;
            border-radius: 4px;
            cursor: pointer;
        }

        /* .results li:first-child {
            padding-top: 15px;
        }

        .results li:last-child {
            padding-bottom: 15px;
        } */

        .results li:hover {
            background-color: #eee;
        }

        .results li:hover .position {
            color: #111;
            border-color: #111;
            box-shadow: 0px 0px 1px inset #111;
        }

        .results li:hover .team {
            color: #111;
        }

        .position {
            background-color: #ddd;
            border: 1px solid #555;
            border-radius: 4px;
            padding: 1px 5px;
            margin-left: 4px;
            color: #555;
            font-size: 11px;
            font-weight: 500;
            letter-spacing: 0.5px;
            text-transform: uppercase;
        }

        .team {
            font-size: 13px;
            color: #888;
            position: absolute;
            right: 10px;
        }

        .profile {
            display: grid;
            grid-template-columns: 1fr auto;
            grid-gap: 20px;
            align-items: center;
            /* border: 1px solid #ddd; */
            border-radius: 4px;
            box-sizing: border-box;
            padding: 20px;
            border: 1px solid #ddd;
            margin: 3px;
        }

        .profile div {
            padding: 0;
            margin: 0;
        }

        .p-name {
            font-size: 18px;
            font-weight: bold;
        }

        .profile .p-team {
            font-size: 14px;
            margin-bottom: 5px;
        }

        .p-jersey {
            font-size: 60px;
            text-align: right;
        }

        .p-number {
            font-size: 30px;
        }

        .p-info {
            font-size: 13px;
            text-transform: uppercase;
        }

        .profile .stats {
            font-size: 13px;
            margin-top: 10px;
        }
              
            
!

JS

              
                const input = document.querySelector("input");
const ul = document.querySelector("ul");
const endpoint =
  "https://api.collegefootballdata.com/roster?team=texas&year=2020";

// clears input value on page laod
input.value = "";

async function getPlayers() {
  const response = await fetch(endpoint);
  const data = await response.json();
  const players = data.filter((player) => player.first_name !== null);

  function findMatches(wordToMatch, players) {
    return players.filter((player) => {
      const regex = new RegExp(wordToMatch, "gi");
      return player.first_name.match(regex) || player.last_name.match(regex);
    });
  }

  function displayMatches() {
    console.log(this.value);
    const matchArray = findMatches(this.value, players);
    const html = matchArray
      .map((match) => {
        const playerName = `${match.first_name} ${match.last_name}`;
        const position = match.position;
        return `<li id="${match.id}">
                                <span>${playerName}</span>
                                <span class="position">${position}</span>
                                <span class="team">Texas Longhorns</span>
                            </li>`;
      })
      .join("");

    this.value === "" ? (ul.innerHTML = "") : (ul.innerHTML = html);

    const resultItems = document.querySelectorAll("li");
    resultItems.forEach((result) =>
      result.addEventListener("click", (e) =>
        displayProfile(e.target.id, players)
      )
    );
  }

  input.addEventListener("keyup", displayMatches);
}

function displayProfile(playerId, players) {
  console.log(playerId);

  const player = players.filter((player) => player.id === playerId);

  const html = player
    .map((player) => {
      return `<div class="profile">
                    <div>
                        <div>
                            <span class="p-name">${player.first_name} ${player.last_name}</span>
                            <span class="position">${player.position}</span>
                        </div>
                        <div class="p-team">Texas Longhorns</div>
                        <div class="p-info">
                            <span>YR ${player.year} | </span>
                            <span>${player.height} | </span>
                            <span>${player.weight}</span>
                        </div>
                    </div>
                    <div>
                        <div class="p-jersey">
                            <span class="p-number">#</span>
                            <span>${player.jersey}</span>
                        </div>
                    </div>
                </div>`;
    })
    .join("");

  ul.innerHTML = html;
  input.value = "";
}

getPlayers();

              
            
!
999px

Console