I have a hidden div in a ctp file.
<div id="UserId" style="visibility:hidden;">
<?php
$UserId = $app['Auth']['User']['id'];
echo $UserId;
?>
</div>
I need to get this $userId value in a .js file.
var user_id = $("#userId").val();
alert(user_id);
But I got empty value. Please help…
I tried with var current_user_id = $("#userId").html();
but it shows the value in the center of the alert box and if i use that value in if condition, it does not return true for the condition.
For eg: say user_id value is 5.
A = 5
if (A == user_id){
alert(1);
} else {
alert(2);
}
It always returns 2.
Either get the value using
.innerHTMLor use an<input />tag to store your value for example:you see
<div>tags don’t have values