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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <!-- bootstrap css -->
 <link rel="stylesheet" href="css/bootstrap.min.css">
 <!-- main css -->
 <link rel="stylesheet" href="css/main.css">
 <!-- google fonts -->
 <link href="https://fonts.googleapis.com/css?family=Courgette" rel="stylesheet">

 <!-- font awesome -->
 <link rel="stylesheet" href="css/all.css">
 <title>Http Methods</title>
 <style>
 </style>
</head>

<body>


 <div class="container">
  <div class="row">
   <div class="col col-md-8 mx-auto">
    <h3 class="text-capitalize text-center mt-3">item form</h3>
    <div class="feedback alert alert-danger text-capitalize text-center">
     alert
    </div>
    <!-- form -->
    <form id='httpForm' class="mb-5 mt-3">

     <div class="input-group mb-3">
      <div class="input-group-prepend">
       <span class="input-group-text"><i class="fab fa-amazon"></i></span>
      </div>
      <input type="text" id='itemInput' class="form-control text-capitalize" placeholder="enter name">
     </div>
     <div class="input-group mb-3">
      <div class="input-group-prepend">
       <span class="input-group-text"><i class="fas fa-image"></i></span>
      </div>
      <input type="text" id='imageInput' class="form-control text-capitalize" placeholder="Image">
     </div>
     <button type="submit" id='submitBtn' class="btn submitBtn btn-block text-capitalize">add item</button>

    </form>
    <!-- end of form -->
    <!-- list  -->
    <div class="mt-5">
     <h3 class="text-capitalize text-center">items</h3>
     <ul class="list-group items">
      <!-- single item -->
      <li class="list-group-item d-flex align-items-center justify-content-between flex-wrap item my-2">
       <img src="img/default.jpeg" id='itemImage' class='itemImage img-thumbnail' alt="">
       <h6 id="itemName" class="text-capitalize itemName">item name</h6>
       <div class="icons">

        <a href='#' class="itemIcon mx-2 edit-icon" data-id=''>
         <i class="fas fa-edit"></i>
        </a>
        <a href='#' class="itemIcon mx-2 delete-icon" data-id=''>
         <i class="fas fa-trash"></i>
        </a>
       </div>
      </li> -->
      <!-- end of single item -->
     </ul>
    </div>
    <!-- end of list -->
   </div>
  </div>
 </div>






 <!-- jquery -->
 <script src="js/jquery-3.3.1.min.js"></script>
 <!-- bootstrap js -->
 <script src="js/bootstrap.bundle.min.js"></script>
 <!-- script js -->
 <script src="js/app.js"></script>
</body>

</html>
              
            
!

CSS

              
                :root {
  --mainWhite: #f5f5f5;
  --mainDark: #333333;
  --mainOrange: #f15025;
  --mainGreen: #90a959;
  --mainRed: #a63d40;
}
body {
  background: var(--mainWhite);
  color: var(--mainDark);
}
.submitBtn {
  color: var(--mainOrange);
  border: 0.1rem solid var(--mainOrange);
  background: transparent;
  transition: all 0.3 ease-in-out;
}
.submitBtn:hover {
  background: var(--mainOrange);
  color: var(--mainDark);
}
.input-group-text {
  background: var(--mainOrange);
}
.edit-icon {
  text-decoration: none !important;
  color: var(--mainGreen);
}
.delete-icon {
  text-decoration: none !important;
  color: var(--mainRed);
}

.itemIcon {
  font-size: 1rem;
}
.itemIcon:hover {
  color: var(--mainDark);
}
.feedback {
   display: none; 
}
.showItem {
  display: block;
}

              
            
!

JS

              
                //get items 

const itemList=document.querySelector('.items');
const httpForm=document.getElementById('httpForm');
const itemInput=document.getElementById('itemInput');
const imageInput=document.getElementById('imageInput');
const feedback=document.querySelector('.feedback');
const items=document.querySelector('.items');
const submtiBtn=document.querySelector('.submitBtn');
let editedItemID=0;

const url="https://5ddfe336bb46ce001434bdde.mockapi.io/items";

httpForm.addEventListener('click',submitBtn);

//submit items

function submitBtn(event){
  console.log('log');
  
  event.preventDefault();

  const itemValue=itemInput.value;

  const imageValue=imageInput.value;


  if(itemValue.length===0 || imageValue.length===0){
    showFeedback('please enter valid values');
  }else{
  
  }
  
}

//load items

document.addEventListener('DOMContentLoaded',function(){
  //
  getItemsAPI(showItems)
});

//show Feedback

function showFeedback(text){

  feedback.classList.add("showItem");
  feedback.innerHTML=`<p>${text}</p>`;
  setTimeout(()=>{
   feedback.classList.remove("showItem"); 
  },3000)

}


//get items
function getItemsAPI(cb){

  const url="https://5ddfe336bb46ce001434bdde.mockapi.io/items";
  //once we have a url, create an instance of xhr object

  const ajax=new XMLHttpRequest();




  ajax.open('GET',url,true);

  ajax.onload=function(){
    if(this.status==200){
    cb(this.responseText);


    }else{
      console.log("Something went wrong");
      
    }
  }

  ajax.onerror=function(){
    console.log('there was an  error');
    
  }

  ajax.send();
}

//show items

function showItems(data){


const items=JSON.parse(data)
 console.log(items);

 let info='';

 items.forEach(item =>{
   info+=`<li class="list-group-item d-flex align-items-center justify-content-between flex-wrap item my-2">
   <img src="${item.avatar}" id='itemImage' class='itemImage img-thumbnail' alt="">
   <h6 id="itemName" class="text-capitalize itemName">${item.name}</h6>
   <div class="icons">

    <a href='#' class="itemIcon mx-2 edit-icon" data-id='${item.id}'>
     <i class="fas fa-edit"></i>
    </a>
    <a href='#' class="itemIcon mx-2 delete-icon" data-id='${items.id}'>
     <i class="fas fa-trash"></i>
    </a>
   </div>
  </li>`
 })

 itemList.innerHTML=info;
 //get Icons


 
}

              
            
!
999px

Console