Sunday 31 December 2017

html - jQuery click function doesn't work after ajax call?





The jQuery click function works fine
here



            id="LangTable">delete



$('.deletelanguage').click(function(){

alert("success");
});



but
if I set some by ajax,
$('.deletelanguage').click doesn't
work.



for
example



function CreateRow(jdata)
{
$('#LangTable').append(' class="deletelanguage">delete
');
}

$.ajax({


url: "/jobseeker/profile/",
success:
CreateRow
});


Now
the $('.deletelanguage').click for the last
is not
working.



jsfiddle example : href="http://jsfiddle.net/suhailvs/wjqjq/">http://jsfiddle.net/suhailvs/wjqjq/



Note:
the CSS works fine here.




I want to
make these newly appended working with jQuery
click.



Answer




The problem is that .click only works for
elements already on the page.
You have to use something like
on if you are wiring up future
elements



$("#LangTable").on("click",".deletelanguage",
function(){

alert("success");
});



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...