jquery not working after ajax post asp.net mvc4 -


here jquery function not working after jquery ajax call. here code

ajax call

 <input type="button" value="comment" class="submitcomment" onclick="additem(this);" /> 

and

<script type="text/javascript">      function additem(data) {                     postdata = $(data).parents().find("textarea");             var input = { "prdhierkey": postdata.parents().find('input[data-attr="prodkey"]').val(),                 "geohierkey": postdata.parents().find('input[data-attr="geokey"]').val(),                 "period": postdata.parents().find('input[data-attr="period"]').val(),                 "comment": postdata.val()                };             $.ajax({                 url: '@url.action("addcomments", "card")',                 type: "post",                 data: json.stringify(input),                 cache: false,                 contenttype: 'application/json; charset=utf-8',                 success: function (result) {                     $(".commentcontainer").html(result);                 }             });           } </script> 

and jquery function not working after ajax call here

$(document).ready(function () {      $(".inputcomment").focus(function () {                     $(this).css("height", "50px");             if ($(this).val() == "add comment") {                 $(this).val("");             }             $(".submitcomment").show();             $(this).addclass("inputactive");         }); }); 

try using delegated event, html coming via ajax call after dom load:

 $(document).on('focus','.inputcomment',function () {                     $(this).css("height", "50px");             if ($(this).val() == "add comment") {                 $(this).val("");             }             $(".submitcomment").show();             $(this).addclass("inputactive");         }); 

or can this:

$('.commentcontainer').on('focus','.inputcomment',function () {                         $(this).css("height", "50px");                 if ($(this).val() == "add comment") {                     $(this).val("");                 }                 $(".submitcomment").show();                 $(this).addclass("inputactive");             }); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -