Alex Rivera | Logout

How to alert using jQuery

Asked 2010-05-10T15:56:11.877
49

This works:

$('.overdue').addClass('alert');

But this doesn't:

$('.overdue').alert('Your book is overdue.'); 

What is the correct jQuery syntax for:

FOR EACH CLASS="overdue"
   alert('Your book is overdue');
NEXT
Edit
Report

1 Answer

94
$(".overdue").each( function() {
    alert("Your book is overdue.");
});

Note that ".addClass()" works because addClass is a function defined on the jQuery object. You can't just plop any old function on the end of a selector and expect it to work.

Also, probably a bad idea to bombard the user with n popups (where n = the number of books overdue).

Perhaps use the size function:

alert( "You have " + $(".overdue").size() + " books overdue." );
answered 2010-05-10T15:58:02.460

Your Answer