Java Script (25) 썸네일형 리스트형 [JavaScript] node/요소 가져오기, 변경, 생성, 삭제하기 자바스크립트는 DOM을 통해 요소(element)를 아래와 같이 조작하며 웹페이지 콘텐츠에 영향을 줄 수 있다. node/요소 내용 가져오기 node/요소 내용 변경하기 node/요소 내용 추가하기 node/요소 내용 삭제하기 1. node/요소 내용 가져오기 자바스크립트에서 div element에 접근하여 내용을 가져올 때는 innerHTML, innerText, textContent 세 가지 속성을 사용할 수 있다. 코드로 확인해보자 - HTML 안녕하세요? 만나서 반가워요. 숨겨진 텍스트 1-1. element.innerHTML function getInnerHTML() { const element = document.getElementById('parent'); alert(element.inner.. [알고리즘] 0829 문제 - Codewars_Is n divisible by x and y? (8kyu) Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero numbers. Examples: 1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 2) n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6 3) n = 100, x = 5, y = 3 => false because 100 is not divisible by 3 4) n = 12, x = 7.. [JavaScript] 부모, 자식, 형제와 요소 찾기 보통 DOM을 조작할 때는 node를 탐색하기 보다는 element를 탐색하고 조작한다. element를 탐색하는 방법에는 다음과 같이 세 가지 방법이 있다. 부모(parent) 노드 자식(child) 노드 형제(sibling) 노드 1. element 탐색 node에는 text, element, 주석 등 여러가지 타입이 있는데 element는 여러 node 타입 중 한 종류이다. element는 , , 와 같은 태그를 사용해서 작성된 노드이다. 1-1. 부모(parent) 요소 탐색 parentElement : 부모 요소를 리턴 1-2. 자식(child) 요소 탐색 children : 자식 요소 목록을 HTML Collection 형태로 리턴 firstElementChild : 자식 요소 중, 첫번째 .. [JavaScript] 선택자 Javascript에서 DOM의 특정 요소(element)를 찾는 방법은 크게 아래와 같다. 아이디 이름을 이용하여 선택하는 방법 클래스 이름을 이용하여 선택하는 방법 태그 이름을 이용하여 선택하는 방법 CSS 선택자를 이용하여 선택하는 방법 #. 선택자 별 선택 방법 선택자 구분 getElementById 아이디 이름으로 선택 getElementsByClassName 클래스 이름으로 선택 getElementsByTagName 태그 이름으로 선택 * 전체 선택자 (*CSS 선택자) # id 선택자 . class 선택자 예시 코드로 알아보기 - HTML 코드 제목 오늘의 날씨는 무엇일까요 rainy sunny cloudy The weather is changeable 1. 아이디 이름을 이용하여 선택하는 .. [알고리즘] 0828 문제 - Codewars_Basic Mathematical Operations (8kyu) Your task is to create a function that does four basic mathematical operations. The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen operation. Examples(Operator, value1, value2) --> output ('+', 4, 7) --> 11 ('-', 15, 18) --> -3 .. [알고리즘] 0827 문제 - Codewars_Keep Hydrated! (8kyu) Nathan loves cycling. Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling.You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value. For example: time = 3 ----> litres = 1 time = 6.7---> litres = 3 time = 11.8--> litres = 5 문제 풀이 function lit.. [JavaScript] 특정 값의 배열 위치(index) 찾기 배열에서 특정 값의 위치 index를 찾는 방법은 아래와 같은 메소드들이 활용된다. indexOf() lastIndexOf() includes() findIndex() 특정 조건을 모두 만족하는 inde를 찾는 방법은 아래와 같다. 반복문 map()과 filter() 조합 reduce() 특정값의 배열 내 위치 찾기 1. indexOf() str.indexOf(searchValue[, fromIndex]) 파라미터 searchValue : 찾으려는 값 fromIndex : 검색을 시작할 index, 입력하지 않으면 0부터 검색 시작 (*optional) 리턴값 배열에서 searchElement와 값과 정확하게 일치하는 첫 번째 element의 index를 반환한다. 찾으려는 값이 배열에 없으면 아래 예시.. [알고리즘] 0826 문제 - Codewars_A needle in the Haystack (8kyu) Write a function findNeedle() that takes an array full of junk but containing one "needle" After your function finds the needle it should return a message (as a string) that says:"found the needle at position " plus the index it found the needle, so: Example(Input --> Output) ["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"] --> "foun.. 이전 1 2 3 4 다음