JQuery - get id of div element with same class name
I need to pick id od selectable when Test1 or Test2 are clicked.
<div class="selectable" id="1">
<span class="ui-state-default">Test1</span></asp:Label>
</div>
<div class="selectable" id="2">
<span class="ui-state-default">Test2</span></asp:Label>
</div>
I try somethnig, but i only get first time good value, i get always same value next times.
$(".selectable").selectable({
stop: function() {
$(".ui-selected", this).each(function() {
alert($(".ui-开发者_运维问答selected").closest("div").attr("id"));
});
}
});
You need to use $(this)
in your .each()
function instead of $(".ui-selected")
:
$(".selectable").selectable({
stop: function() {
$(".ui-selected", this).each(function() {
alert($(this).closest("div").attr("id"));
});
}
});
Otherwise only the first .ui-selected
(and consequently the first parent div
) will be looked at, and you'll only get the first div
's ID.
精彩评论