Skip to content Skip to sidebar Skip to footer

JQuery Syntax Error, Unrecognised Expression

syntax error, unrecognised expression: #2015-11-30|1112|1 I have an anchor tag with an Id of '2015-11-30|1112|1' that I would like to apply a class to. I am doing the same method

Solution 1:

You should escape the special chracters in your id using \\, check example bellow.

Hope this helps.


console.log( $("#2015-11-30\\|1112\\|1").text() );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="2015-11-30|1112|1">Div text example</div>

Solution 2:

For your current code to work, you don't have to use that id selector since you already have the reference of the object inside the event function.

$(document).ready(function() {
  $("#tbl_calendar").on("click", "a", clickAppointment);

  function clickAppointment(eventData) {
    //"this" will have a reference to the clicked object
    $(this).addClass("selected");
  }
});

Not sure about your HTML, but considering something similar to the below one.

<ul id="tbl_calendar">
  <li>
    <a id="2015-11-30|1112|1">Click</a>
  </li>
</ul>

Working sample


Post a Comment for "JQuery Syntax Error, Unrecognised Expression"