Skip to content

TypeError: $(…).children is not a function

I try to select certain DOM element with jQuery

the html

        <script src="//"> </script>
      <nav id="nav" class="navigator">
      <h1>Nav Header</h1>

      <ul class="nav-list">
        <li class="nav-item"><a >Item #1</a></li>
        <li class="nav-item active"><a href="#2">Item #2</a></li>

I want to select Item #1 I used


I got

TypeError: $(...).children is not a function

What’s wrong here ?


You need to include jQuery in your page.

Most browsers nowadays include a $() function in their console by default for easy element selection, but this simply maps to document.getElementById().

The value returned will not have a .children() method.

Additionally, if you load an HTML page directly from your file system, you need to include the http:// for CDN script URLs. Otherwise, your browser will try to find the .js file on your local system.