jQuery addClass example

Change class name on click in jQuery

by Victor

HTML

<div class="preview preview--centered">
  <div class="preview__inner">
    <div class="preview__inner__logo"></div>
    <div class="preview__inner__body">
    body text
    <br>
      <div class="preview__inner__body__button">Testing</div>
    </div>
  </div>
  <div class="preview__close">X</div>
</div>

SCSS

.preview {
  background: grey;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  
  &--centered {
    text-align: center;
  }
  
  &__inner {
    
    background-color: grey;
    padding: 0;
    height: 66vh;
    max-width: 400px;
    width: 100%;
    
    &__logo {
      width: 20px;
      height: 20px;
      background: orange;
      margin: 0 auto 2rem;
    }
    
    &__body {
      background: white;
      padding: 1rem;
      &__title {
        font-weight: bold;
      }
      
      &__button {
        background:blue;
        display: inline-block;
        margin: 1rem auto 0;
        width: 100px;
        padding: 5px;
        border-radius: 4px;
      }
    }
  }
  
  &__close {
    
    position: absolute;
    top: 0;
    right: 0;
    padding: 1rem;
  }
  
}