开发者

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

开发者 https://www.devze.com 2022-12-24 04:20 出处:网络
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:

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

精彩评论

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