How to grab the ID of a selected DIV
Hi - I'm trying to use the "selectable" feature - and need to find the IDs of the DIVs which have been selected.
When I run the code below, all I keep getting is the ID of the first DIV in the selectable DIV (ie. 2011-01-01).
Thank you for any help,
Mark
-
<!
DOCTYPE html>
-
<
html
lang
="en">
-
<
head
>
-
<
meta
charset
="utf-8">
-
<
title
>
jQuery UI Selectable - Serialize
</
title
>
-
<
link
rel
="stylesheet"
href
="../../themes/base/jquery.ui.all.css">
-
<
script
src
="../../jquery-1.5.1.js"></
script
>
-
<
script
src
="../../ui/jquery.ui.core.js"></
script
>
-
<
script
src
="../../ui/jquery.ui.widget.js"></
script
>
-
<
script
src
="../../ui/jquery.ui.mouse.js"></
script
>
-
<
script
src
="../../ui/jquery.ui.selectable.js"></
script
>
-
<
link
rel
="stylesheet"
href
="../demos.css">
-
<
style
>
-
#selectable
.ui-selecting
-
{
-
background
:
green
;
-
}
-
#selectable
.ui-selected
-
{
-
background
:
red
;
-
color
:
white
;
-
}
-
#selectable
-
{
-
list-style-type
:
none
;
-
margin
:
0
;
-
padding
:
0
;
-
width
:
60%
;
-
}
-
#selectable
div
-
{
-
margin
:
3px
;
-
padding
:
1px
;
-
float
:
left
;
-
width
:
80px
;
-
height
:
30px
;
-
font-size
:
1em
;
-
text-align
:
center
;
-
}
-
</
style
>
-
<
script
>
-
$(
function
() {
-
$(
"#selectable"
).selectable({
-
stop:
function
() {
-
var
result = $(
"#result"
).empty();
-
var
result2 = $(
"#result2"
).empty();
-
$(
".ui-selected"
,
this
).each(
function
() {
-
var
index = $(
"#selectable div"
).index(
this
);
-
result.append(
" #"
+ (index + 1));
-
var
txt = $(
"#selectable div"
).attr(
"id"
);
-
result2.append(txt);
-
});
-
}
-
});
-
});
-
-
</
script
>
-
</
head
>
-
<
body
>
-
<
div
class
="demo">
-
<
p
id
="feedback">
-
You selected:
<
span
id
="result"></
span
><
br
/>
-
You selected:
<
span
id
="result2"></
span
>
-
</
p
>
-
<
div
id
="selectable"
style
="
border-width
: thick;
margin-bottom
: 5px">
-
<
div
id
="2011-01-01">
-
Element 1
</
div
>
-
<
div
id
="2011-01-02">
-
Element 2
</
div
>
-
<
div
id
="2011-01-03">
-
Element 3
</
div
>
-
<
div
id
="2011-01-04">
-
Element 4
</
div
>
-
<
div
id
="2011-01-05">
-
Element 5
</
div
>
-
<
div
id
="2011-01-06">
-
Element 6
</
div
>
-
</
div
>
-
</
div>
-
</
body
>
-
</
html
>