开发者

sending a variable through jquery.get function depending on which div is clicked

Heres the markup:

<div id='0203' class='threadWrapper'>
<div class='littleme'>

I am trying to send the id of a parent div as a parameter in jquery.get function:

$('.littleme').click(function开发者_StackOverflow中文版**()**{
var id = $(this).closest("div").attr("id");
$.get("PHP/viewedThread.php", {viewedURLID: id});
});

and am getting rather lost I'm afraid.

...ammendment... $(this).closest(".threadWrapper").attr("id");


I am guessing (not tested) that the closest is returning itself (".littleme") which without any id. If you need to target the parent div, try using parent or parents.


UPDATE

The Closest is acutally started from Current node, so, it is not going to look for parent but probably the next div follows.

quote from documentation

Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜