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).

Sammyjo20
  • 79
  • 2
  • 9
  • the naming of your ids is going to cause issues. consider using classes or just dropdownnum1, dropdownnum2 etc. – Cory Dec 15 '15 at 18:23

2 Answers2

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.

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • 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. – Praveen Kumar Purushothaman Dec 15 '15 at 19:01
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);
}
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252