views:

79

answers:

3

hi all,

I have a div called album_number_xx (xx being digits).

this div contains another set of divs, each one representing an image with caption and other details.

I need to allow the user to reorder images by drag and drop, and then update the database with the new order.

using jQuery sortable and serialize, I'm able to get the sequence of images on update. But don't know how to get the album_id, (the xx in the name of the container div).

I though that maybe I can grab the name of that div, store it in variable and then cut the last digits, but don't know how to do it.

any ideas?

thanks, Patrick

A: 

I don't know how you're grabbing the div name, but if you have it in a variable:

var albumId = divNameVariable.split('_')[2];
Mark B
A: 
var name = $('div[id^=album_number]').attr('id');
var num = parseInt(name.substr(name.lastIndexOf('_') + 1));
Scott Evernden
A: 

Based on Scott Evernden answer you can do it on click event:

$(document).ready
(function()
{
    var albums = $("div[id^='album_number']").click
    (function()
    {
     var id = $(this).attr('id');
     var numberId = id.substr(id.lastIndexOf('_') +1);
     alert(numberId);
    });
});
evelio