JavaScript jQuery Basics Working with jQuery Collections Working with jQuery-Specific Selectors

Akshay Alok
Akshay Alok
7,854 Points

I need help with jQuery's syntax

I wanted to select an li element which was being hidden by CSS, and then display it using jQuery. I know I must be doing something really stupid so I apologize in advance...

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
    <h2>Star Trek Characters</h2>

    <ul class="character-list">
        <li>Captain Jean Luc Picard</li>
        <li>Data</li>
        <li>Worf</li>
        <li>Dr. Crusher</li>
    </ul>

    <div>I am supposed to stay hidden!</div>    

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
let $hidden = $('li:hidden');
$hidden.show();

2 Answers

Pascal Breitrück
PRO
Pascal Breitrück
Pro Student 3,204 Points

Hey Friend,

The jQuery Syntax for this is $("li:hidden").show();

Greets Pascal

Akshay Alok
Akshay Alok
7,854 Points

Yeah, I saw the same thing in another question, and it worked!

But I still don't know why my code didn't.

Pascal Breitrück
PRO
Pascal Breitrück
Pro Student 3,204 Points

I think it is a bug your code should work. Because your code is fine .