0

I have a jquery function to toggle "ReplyComment" div.

function addcommentdiv() {
    $('.in').click(function () {
        var $this = $(this),
            $reply = $this.next('.ReplyComment');
        var cevapladisplay = $reply.css('display');
        $reply.toggle();

    });
}
addcommentdiv();

$(document).ready(function () {
    addcommentdiv();
});

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(function () {
    addcommentdiv();
});

...

<ul class="chats">
 <li class="in" >
        blablabla
 </li>
 <div class="ReplyComment" id="ReplyComment">
     blablabla
 </div>
 </ul>

This function sometimes work sometimes doesn't.Shortly not working smoothly. I can't understand.(inside updatepanel and datalist)

serdar
  • 454
  • 1
  • 8
  • 26

1 Answers1

2

It's possible that you are adding the click handlers multiple times. To avoid the issue completely, I would recommend using event delegation:

$(document).ready(function() {
    $(document).on('click', '.in', function () {
        var $this = $(this),
            $reply = $this.next('.ReplyComment');
        var cevapladisplay = $reply.css('display');
        $reply.toggle();

    });
});

This will prevent you from needing to rebind the events after every UpdatePanel refresh.

Jason P
  • 26,984
  • 3
  • 31
  • 45