A Pen by Tom

Thumbnail
This awesome code was written by tcb75, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright tcb75 ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Tom</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id='frame'>
  <input type='text' id='elem' placeholder='Enter Text'/>
</div>

<input type='button' id='btn' value='Change'/>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/tcb75/a-pen-by-tom-xjVNBZ */
#elem {
  margin: 5% 5% 5% 5%;
  border-style: solid;
  border-width: 2px;
  border-color: indianred;
  padding: 1% 1% 1% 1%;
  border-radius: 12px;
  font-family: avenir;
  font-size: 18px;
}

/*Downloaded from https://www.codeseek.co/tcb75/a-pen-by-tom-xjVNBZ */

const change = (el) => {
  var text = null;
  if (el.children[0].value == "") {
    text = el.children[0].placeholder;
    el.innerHTML = `<p>${text}</p>`;
  } else if (el.children[0].value != "") {
    text = el.children[0].value;
    el.innerHTML = `<p>${text}</p>`;
  } else if (el.children[0].textContent != "") {
    text = el.children[0].textContent;
    el.innerHTML = `<input type='text' placeholder=${text}/>`;
  }
}

var frame = document.getElementById('frame');
var btn = document.getElementById('btn');

function doChange(elem) {
  change(elem);
};

Comments