Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I shift an icon or button onclick on it

How can we shift a button or icon towards the right and display a cart or any things that we created in button or icon place? for example, I made a cart containing students’ info as shown in the image below.
enter image description here

I am trying to shift that icon towards the right onclick on that plus button and display that cart in icon position. and am expecting that your contributions towards this issue will help me to move forwards

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

function addNewStudent() {
  const button = document.querySelector('button.icon');

  const studentDiv = document.createElement('div');
  studentDiv.className = 'student';
  studentDiv.innerHTML = '<b>New Student</b>';

  button.insertAdjacentElement('beforebegin', studentDiv);
}
.container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.student {
  margin: 10px;
  padding: 10px;
  background-color: #ccc;
  border-radius: 8px;
}

.icon {
  margin: 10px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer
}
<div class="container">
  <div class="student">Student Card</div>
  <div class="student">Student Card</div>
  <button class="icon" onclick="addNewStudent()">+</button>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading