I have this code, where if click on .comments depending on if having prior comments...it loads the comments + a comment form, or just a form (no comments) in .LastComments
HTML
<div class="comment" data-number_comments="7" data-user="Joe">
[Click to comment]
</div>
<div class="LastComments"></div>
JQUERY
$('.comment').on('click', function() {
var user = $(this).data("user");
var number_comments = $(this).data("number_comments");
if (number_comments) {
$(".LastComments").load(url, {
vars
}, /*Load_newform here*/ )
} else {
/*Load_newform here*/
}
});
FUNCTION
function Load_newform() {
form = "<form>Hi " + user + " post a comment </form>";
$(".LastComments").append(form);
}
PROBLEM
The function gets values from the .data returned so It doesnt show the user value and others I'm working with. How do I retrieve the values to make it work correctly?
.data(user)value. Now I want to put this function outside of the click event and thisproblem shows upuseras an argument to theLoad_newform()functionfunction doesnt recognize .data() value jquery-> this title is wrong. The problem is with scoping.