Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  105] [ 1]  / answers: 1 / hits: 44325  / 9 Years ago, wed, march 11, 2015, 12:00:00

I try to select a certain DOM element with jQuery.


The HTML content:


<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
</head>
<body>
<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>
</ul>
</nav>
</body>
</html>

I want to select Item #1. I used


$('.nav-list').children()

I got



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



What's wrong here?


More From » jquery

 Answers
15

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.


[#67471] Tuesday, March 10, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madalyngriseldas

Total Points: 167
Total Questions: 92
Total Answers: 85

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;