I have records that are being looped through and sent to the html file via json_encode
. For each record, I have a data-attribute that I am storing the record id. What I am trying to accomplish is when the user clicks "Edit" (.recEdit
) then I can obtain the id (data-recId
). I am trying to do this with a click function, utilizing the $(this)
and parent()
functions.
What am I doing wrong?
Here is the looped code from the php file:
$html .= '<div class="recentProjectCont" data-recId="'.$recProjId.'">';
$html .= '<div class="recProjInfoCont">';
$html .= '<div class="recInfoCont1">';
$html .= '<span class="recProjName recBaseFormat">'.$recProjName.'</span>';
$html .= '</div>';
$html .= '<div class="recInfoCont2">';
$html .= '<span class="recInfoStat recBaseFormat">'.$recProjStat.'</span>';
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="recEdit">Edit</div>';
$html .= '</div>';
Then the click function where I am attempting to obtain the id.
$(document.body).on('click', '.recEdit' ,function() {
var projID = $(this).parent().data('recId');
console.log('Project ID is..... ' + projID);
});