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
jQuery Alert: Different Ways jQuery. Probably one of the most underated functions, but certainly the most used, is jquery. Alert(). Also known as a jQuery command box or system popup window, jQuery alerts contain text information displayed to the user.
The alert() method displays an alert box with a message and an OK button. The alert() method is used when you want information to come through to the user.
Type "alert ("Hey, " + name + "!");". This line of code will add the variable "name" to the word "Hey, "(with the space at the end), and then add "!" to end the sentence (not required). For example, if the user inputs "Trevor" as the value of the variable "name", the alert will say "Heya, Trevor!".
$(".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." );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With