0

This is quite simple but I being not very efficient with jQuery finding it hard to make it work....

I want a notification popup to be displayed (Just as facebook) which tells the user that he have earned some points.

I am using WordPress and the code for popup is working fine, which is below.

jQuery.noticeAdd({
    text: " Congratulations! You Have Just Earned 5 More Points",
    stay: false
});

However i want the popup to be displayed once an specific button is clicked. the Class for the button is comment-reply-link.

So i wrote this code

$(".comment-reply-link").click(function() {
    jQuery.noticeAdd({
        text: " Congratulations! You Have Just Earned 5 More Points",
        stay: false
    });
});

But this code doesn't works.. Did I made any mistake?? How can i make the notification popup to appear only when the button with the particular class is clicked.

2 Answers 2

3

Please try this both code one by one if this will work

first code

$(".comment-reply-link").click(function() {
    $.noticeAdd({ text: " Congratulations! You Have Just Earned 5 More Points",stay: false}); 
}); 

second code

jQuery(".comment-reply-link").click(function() {
    jQuery.noticeAdd({ text: " Congratulations! You Have Just Earned 5 More Points",stay: false}); 
}); 
Sign up to request clarification or add additional context in comments.

1 Comment

Its not working.. although if i use simple alert function of jquery, that works... So is it an issue with my notification code or is it some jquery conflict?
0

Try

$(document).on( "click", ".comment-reply-link", function() {
    jQuery.noticeAdd({
        text: " Congratulations! You Have Just Earned 5 More Points",
        stay: false
    });
});

$(".comment-reply-link").click( attaches a "click" handler on the elements that match ".comment-reply-link" at the time the selector is ran.

7 Comments

how will this fix this issue? I'm not really questioning that it will I'd just like to understand so that I can know for myself if I ever run into this in the future.
@Jared It attaches the "click" handler on document (which always exists and cannot be removed). But the handler is only fired if an element matching selector .comment-reply-link was in the propagation path when the document was clicked.
Given the code he listed would the element not have to exist for the click event to be fired on it?
@Jared It doesn't matter if the elements exist or not when my code is ran. The evaluation of existence is done at the time clicks happen as opposed to being evaluated at the time the handler attaching code is ran.
@Esailija I used your code but that doesn't worked. however if i just use a simple alert function.. that worked without any issue.... is there any issue with my notifying code???
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.