Dynamically generated content in the web page contains an onclick action not working
please see the code below link is generated via ajax call based on one dropdown selection
1 |
<p style="padding-left:10px;cursor: pointer;" class="file_download" uploaded_file_name="'.$data->uploaded_file_name.'" uploaded_path="'.$data->uploaded_path.'" >'.$data->filename.'</p> |
file download code looks like as below
1 2 3 4 5 6 7 |
$('.file_download').click(function (e) { var uploaded_file_name = $(this).attr('uploaded_file_name'); var file_path=$(this).attr('uploaded_path'); $('#download_hidden_filename').val(uploaded_file_name); $("#download_hidden_file_path").val(file_path); $('#upload_form_submit').submit(); }); |
The above code is not firing the download action Solution: change the first line of code-instead of click add on action
1 2 3 4 5 6 7 |
$(document).on("click", '.file_download', function(event) { var uploaded_file_name = $(this).attr('uploaded_file_name'); var file_path=$(this).attr('uploaded_path'); $('#download_hidden_filename').val(uploaded_file_name); $("#download_hidden_file_path").val(file_path); $('#upload_form_submit').submit(); }); |