jQuery + ASP.NET: jQuery click event doesn't fire -
i'm having issue using jquery within asp.net website. want bind common click handler multiple similar elements (generated through listview familiar asp.net). assumption use class selector follows (as example):
$('.standard-group').click(function () { alert($(this).attr("id")); });
this relates series of divs having class:
<div class="standard-group"> content </div> <div class="standard-group"> other content </div>
furthermore, content generated inside contentplaceholder , merged master page (2 nested master pages actually). i've tried putting click handler between <script></script>
tags inside second contentplaceholder injects it's content <head>
section of page, tried putting content in main contentplaceholder no avail. ends happening generated page loads correctly , can inspect source , see function there, no event raised. suspect it's master page/server processing scenario, can't pinpoint it.
any out there?
your script adding event executing before element being created, can use on() delegate event document.
$(document).on('click', '.standard-group', function () { alert($(this).attr("id")); });
delegated events
event handlers bound selected elements; must exist on page @ time code makes call .on(). ensure elements present , can selected, perform event binding inside document ready handler elements in html markup on page. if new html being injected page, select elements , attach event handlers after new html placed page. or, use delegated events attach event handler, described next. reference
Comments
Post a Comment