开发者

Jquery prev appending to many elements

I have a listview that outputs as a table. Inside of each <td> I have a <div> which contains a <hidden> element.

When a sibling of that element is clicked I have it read the hidden value of the hidden element with jquery.prev().

It does the first element fine, but when I click on another element it appends the first element i click orginally. Right now i am testing so i have a alert call the variable for testing and I get two alerts with the value of the hidden element the first one i clicked and now the second. this var continues to build. how do I just have prev get that one value?

Here is my markup:

          <div id="HypeShareAlbum" style="padding: 0;margin:0">
              <input type="hidden" value="<%#Eval("ID") %>"/>
              <asp:HyperLink runat="server" Text="Share Album"></asp:HyperLink>
          </div>

And my corresponding client code:

 $('#HypeShareAlbum a').click(function () {
            //Create/clear variiable for albumID
            var albumvalue = '';
            //Set Variable for albumid
            albumvalue = $(this).prev().val();
            //Dialog Settings
            var dialogsettings = {
                width: 447,
                minheight: 100,
                hei开发者_如何学Goght: 356,
                position: ["center"],
                close: function () {
                    $('#ClonedEmail').html('');
                }
            };
            //DIALOG FOR SHARING ALBUM STARTS HERE
            //Show Share Album Dialog
            $('#ShareDialog').dialog(dialogsettings);
            //When Focusing out of main email check if exist
            $('#addemail input[type=text]').focusout(function () {
                //Checks main email
            });
            //Click Event for Adding more Emails to dialog
            $('#AddMoreEmails').click(function () {
                //Append Email
                $('#addemail').clone().appendTo($('#ClonedEmail'));
                //Remove and bind back fousout event
                $('#ClonedEmail input[type=text]').unbind('focusout');
                $('#ClonedEmail input[type=text]').focusout(function () {
                    //Check email and let user no if email is found or not
                });
            });
            //Cancel Dialog
            $('#CancelEmailShare').click(function () {
                $("#ShareDialog").dialog("close");
            });
            //Send Email Ajax and Cancel Dialog
            $('#SendEmailShare').click(function () {
                alert(albumvalue);
            });
            //DIALOG FOR SHARING ALBUM ENDS HERE
        });


instead of adding this value to a alert, i added it to a textbox for testing and it worked fine. Not sure why on a alert it was coming up multiple times but, its now working ok.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜