0

This is my HTML:

<div class="dropdown-text" id="dropdownopen" onclick="dropdownopen(0)">
    <div class="inside">+ Show Content</div>
</div>

<div class="dropdown" id="dropdownnum(0)">
     <div class="inner">INSERT DROPDOWN CONTENT IN HERE</div>
</div>

And here is my JS (Jquery):

function dropdownopen(param) {
    $('#dropdownnum('+param+')').fadeOut(300);
}

The #dropdownnum(0) div is display:none; by default, so this should work, but I get the error:

Uncaught Error: Syntax error, unrecognized expression: #dropdownnum(0).

1
  • the naming of your ids is going to cause issues. consider using classes or just dropdownnum1, dropdownnum2 etc. Commented Dec 15, 2015 at 18:23

2 Answers 2

1

The ( and ) needs to be escaped.

function dropdownopen(param) {
    $('#dropdownnum\\('+param+'\\)').fadeOut(300);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dropdown-text" id="dropdownopen" onclick="dropdownopen(0)">
    <div class="inside">+ Show Content</div>
</div>

<div class="dropdown" id="dropdownnum(0)">
     <div class="inner">INSERT DROPDOWN CONTENT IN HERE</div>
</div>

But you really should pick a different naming scheme for your ids so you do not have to do this.

Sign up to request clarification or add additional context in comments.

1 Comment

Have your vote, better let's not argue for this silly thing. It is better to avoid such a way of writing the values. And you too agree with it. :) The OP is doing it unknowingly. It's okay that now they understood.
0

You cannot have special characters like ( and ) in a value of id. Please try changing your code to:

<div class="dropdown-text" id="dropdownopen" onclick="dropdownopen(0)">
    <div class="inside">+ Show Content</div>
</div>

<div class="dropdown" id="dropdownnum-0">
     <div class="inner">INSERT DROPDOWN CONTENT IN HERE</div>
</div>

function dropdownopen(param) {
    $('#dropdownnum-'+param).fadeOut(300);
}

4 Comments

Are you looking at the HTML4 or HTML5 restrictions. :)
@epascarello Do you say W3C Working Draft is wrong? w3.org/TR/html4/types.html#type-id
Oh yeah.. That's HTML4. Here's HTML5: w3.org/TR/html-markup/syntax.html#syntax-attribute-value
Bro, just leave it. I am giving you an upvote for so much of argument. Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.