-1

I am getting this error:

Error: Syntax error, unrecognized expression: #mas137-0-0-0-1|2|7|9|13

in the script below. I don't understand why "ID" can not be "137-0-0-0-1|2|7|9|13". I use "|" delimiter because there are other conflicts if I use "," or ":".

$(document.body).on('click','.load_more_posts',function() {
var ID = $(this).attr("id");
if(ID) {
$("#mas"+ID).html('<img src="/images/loading.gif" />');
$.ajax({
type: "POST",url: "/show_more.php",data: "vid="+ ID, cache: false,
success: function(html){
$("#mas"+ID).remove();
$("div#posts").append(html);

}});

} else {
$(".masw").html('-');
}
return false;
});
user1406271
  • 297
  • 1
  • 3
  • 12

1 Answers1

1

You have to escape the symbols that are not accepted. One way to do it is

var ID = $(this).attr("id").replace(/\|/g, '\\|');

I would still recommend you use the standard recommended symbols for ID attributes.

var i = $('div').attr('id').replace(/\|/g, '\\|');
var t = $('#mask'+i).text();
alert(t);
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div id="137-0-0-0-1|2|7|9|13"></div>
<div id="mask137-0-0-0-1|2|7|9|13">Text</div>
Spokey
  • 10,974
  • 2
  • 28
  • 44