JS Reference

JS by Category JS by Alphabet

JavaScript

JS Array JS Boolean JS Classes JS Date JS Error JS Global JS JSON JS Math JS Number JS Operators JS RegExp JS Statements JS String

Window

Window Object Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

DOM Document DOM Element DOM Attributes DOM Events DOM Event Objects DOM HTMLCollection DOM Style
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundRepeat backgroundClip backgroundOrigin backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap cssFloat font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

Web APIs

API Console API Fullscreen API Geolocation API History API MediaQueryList API Storage

HTML Objects

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

Other References

CSSStyleDeclaration JS Conversion


HTML DOM 문서 querySelector()

첫 번째 <p> 요소를 가져옵니다.

document.querySelector("p");

class="example"인 첫 번째 요소를 가져옵니다.

document.querySelector(".example");

아래에 더 많은 예가 있습니다.


정의 및 사용

querySelector()메서드는 CSS 선택기와 일치하는 첫 번째 요소를 반환합니다.

모든 일치 항목(첫 번째 항목뿐만 아니라) 을 반환하려면 querySelectorAll()대신 사용하십시오.

둘 다 NodeListquerySelector()querySelectorAll()반환합니다 .

선택기가 유효하지 않으면 둘 다 SYNTAX_ERR 예외 querySelector()를 throw합니다.querySelectorAll()


HTML DOM NodeList / HTMLCollection

HTMLCollection과 NodeList의 차이점

NodeListHTMLCollection 은 모두 문서에서 추출한 노드(요소)의 배열과 유사한 컬렉션(목록)입니다 . 노드는 인덱스 번호로 액세스할 수 있습니다. 인덱스는 0에서 시작합니다.

두 개체 모두 목록의 요소 수를 반환 하는 길이 속성을 가지고 있습니다.

HTMLCollection은 라이브 컬렉션입니다 . DOM의 목록에 <li> 요소를 추가하면 HTMLCollection의 목록도 변경됩니다.

NodeList는 정적 컬렉션입니다 . DOM의 목록에 <li> 요소를 추가해도 NodeList의 목록은 변경되지 않습니다.

getElementsByClassName()및 메서드 getElementsByTagName() HTMLCollection을 반환합니다.

querySelector()및 메서드 querySelectorAll() NodeList를 반환합니다.


통사론

document.querySelector(CSS selectors)

매개변수

Parameter Description
CSS
selectors
Required.
One or more CSS selectors.

CSS selectors select HTML elements based on id, classes, types, attributes, values of attributes etc.
For a full list, go to our CSS Selectors Reference.

For multiple selectors, separate each selector with a comma (See "More Examples").

반환 값

유형 설명
물체CSS 선택기와 일치하는 첫 번째 요소가 있는 NodeList .
일치하는 항목이 없으면 null반환됩니다.


더 많은 예

class="example"을 사용하여 첫 번째 <p> 요소를 가져옵니다.

document.querySelector("p.example");

id="demo"로 요소의 텍스트를 변경합니다.

document.querySelector("#demo").innerHTML = "Hello World!";

부모가 <div> 요소인 첫 번째 <p> 요소를 선택합니다.

document.querySelector("div > p");

"target" 속성이 있는 첫 번째 <a> 요소를 선택합니다.

document.querySelector("a[target]");

첫 번째 <h3> 또는 첫 번째 <h4> 선택:

<h3>A h3 element</h3>
<h4>A h4 element</h4>
document.querySelector("h3, h4").style.backgroundColor = "red";

첫 번째 <h3> 또는 첫 번째 <h4> 선택:

<h4>A h4 element</h4>
<h3>A h3 element</h3>
document.querySelector("h3, h4").style.backgroundColor = "red";

브라우저 지원

document.querySelector()DOM 레벨 1(1998) 기능입니다.

모든 브라우저에서 완벽하게 지원됩니다.

Chrome IE Edge Firefox Safari Opera
Yes 9-11 Yes Yes Yes Yes