Jquery Why is this var definition giving uncaught exception
Console.log is giving un开发者_如何学运维caught exception: Syntax error, unrecognized expression: #.
This seems to be caused by $('#'+elmid+' div')
. if i remove # then i do not get this error. What is causing this.
$(".abs").live('click',
function(e) {
var elmid = $(this).attr('id');
var editableid = $('#'+elmid+' div').attr('id');
console.log(editableid);
});
My guess is that the clicked element does not actually have an id
attribute. This means that your selector is # div
, which is obviously an invalid jQuery selector. You should use find
instead:
var editableid = $(this).find('div').attr('id');
精彩评论