Korean_hamster
지현의 개발자 성장과정
Korean_hamster
전체 방문자
오늘
어제
  • 분류 전체보기 (122)
    • Front-End Developer (79)
      • Project (12)
      • HTML (8)
      • CSS (17)
      • Computer Science (9)
      • JavaScript (20)
      • React (13)
    • 이런저런 생각 (7)
    • 주간 성장회고 (24)
    • English (0)
    • 리뷰 (2)
    • Books (5)

블로그 메뉴

  • 방명록

공지사항

인기 글

태그

  • HTML
  • fetch
  • flex
  • 비전공개발자
  • sass
  • 리액트
  • 깃헙
  • CSS
  • CS
  • 프론트앤드스쿨
  • 라우터
  • 멋사
  • 반응형웹
  • 비전공자개발자
  • 깃
  • AtomicHabits
  • 멋쟁이사자처럼
  • 면접관님
  • 프론트앤드
  • js

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Korean_hamster

지현의 개발자 성장과정

Front-End Developer/JavaScript

(DOM)click이벤트로 HTML요소 텍스트와 CSS스타일 변경하기

2022. 5. 16. 13:43

 

const radioRow = document.querySelector('#cheat0-option1');
const radioRowReverse = document.querySelector('#cheat0-option2');
const radioColumn = document.querySelector('#cheat0-option3');
const radioColumReverse = document.querySelector('#cheat0-option4');

const flexDirection = document.querySelector('.day');
const dayBox = document.querySelector('.cheat0');


radioRow.addEventListener('click', function () {
  flexDirection.textContent = 'flex-direction: row;';
  dayBox.style.flexDirection = 'row';
});

radioRowReverse.addEventListener('click', function () {
  flexDirection.textContent = 'flex-direction: row-reverse;';
  dayBox.style.flexDirection = 'row-reverse';
});

radioColumn.addEventListener('click', function () {
  flexDirection.textContent = 'flex-direction: column;';
  dayBox.style.flexDirection = 'column';
});

radioColumReverse.addEventListener('click', function () {
  flexDirection.textContent = 'flex-direction: column-reverse;';
  dayBox.style.flexDirection = 'column-reverse';
});

일단 구현을 했는데, 반복된 동작을 처리하는 일이니 for each문을 사용해서 코드를 더 효율적으로 만들 수 있을 것 같다.

다시한번 해봐야겠다. 

 

저작자표시

'Front-End Developer > JavaScript' 카테고리의 다른 글

함수: 기본중의 기본 정리하기  (0) 2022.05.18
preventDefault속성으로 우클릭 제어하기  (0) 2022.05.16
하드코드->forEach->이벤트 위임 [점점 나아지는 코드 맛보기]  (0) 2022.05.14
blur와 click을 같이 쓸 때, 내 맘대로 안되는 이유  (0) 2022.05.13
DOM이란 무엇인가  (0) 2022.05.13
    Korean_hamster
    Korean_hamster
    Keep pushing myself to the limits

    티스토리툴바