Your Search Results


    Returns the first element that is a descendant of the element on which it is invoked that matches the specified group of selectors.


    element = baseElement.querySelector(selectors);
    • element and baseElement are element objects.
    • selectors is a group of selectors to match on.


    In this example, the first style element which either has no type or has type text/css in the HTML document body is returned:

    var el = document.body.querySelector("style[type='text/css'], style:not([type])");


    Returns null if no matches are found; otherwise, it returns the first matching element.

    Throws a SYNTAX_ERR exception if the specified group of selectors is invalid.

    querySelector() was introduced in the WebApps API.

    The string argument passed to querySelector() must follow CSS syntax. See document.querySelector for concrete examples.

    Browser compatibility

    Browser Support Notes
    Internet Explorer 8 CSS 2.1 selectors only (IE8)
    Firefox (Gecko) 3.5 (1.9.1)  
    Opera 10  
    Chrome 1  
    Safari (WebKit) 3.2 (525.3)


    See also

    Document Tags and Contributors

    Last updated by: Sheppy,
    Hide Sidebar