开发者

Jquery Why is this var definition giving uncaught exception

开发者 https://www.devze.com 2023-02-07 04:05 出处:网络
Console.log is giving un开发者_如何学运维caught exception: Syntax error, unrecognized expression: #.

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消