tags:

views:

42

answers:

2

I use this snippet to show a dialog. This works great however: the title is going to be set only for the first time I click the table cell. After reloading the page again the title is set - for one time. Ad infinitum...

$(document).ready(function() {
    $("td[id^='_ctl0_tbl_content_reportid_']").click(function() {
        var tokens = this.id.split('_');
        var last_index = tokens.length - 1;
        var _dialog = $("#reportid_dialog_" + tokens[last_index]);
        var _title = _dialog.attr("title");

        _dialog.dialog({
            modal: true,
            closeText: 'Hide',
            width: 450,
            title: _title
        });
    });
)};

I use jQuery 1.4.2 with jQuery-ui 1.8.2 Maybe there is somebody to tell me what I'm doing wrong.

+2  A: 

dialog() moves the element you're passing to it, so that it's no longer matched by the selector. Might that be it?

David Hedlund
You are right. The div inside the cell disappears after the first click.
tfl
I moved the title out of the div into a new div of the next cell. Now it works.
tfl
One last comment: The variable _dialog contains more then just the (invalid) attribute title but the whole text the dialog displays. And this text was always there although Firebug showed me that the whole div was gone.
tfl
+1  A: 

I think your running into a dual selector issue. Since your selecting:

$("#reportid_dialog_" + tokens[last_index]);

The second time you click on the table cell and call dialog() there is 2 instances of #reportid_dialog_ which would lead to id's clashing when you attempt to set attrs

nicholasklick