Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alert using jQuery

Tags:

jquery

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 
like image 668
Phillip Senn Avatar asked May 10 '10 15:05

Phillip Senn


People also ask

Can we call alert in jQuery?

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.

How do you do an alert in HTML?

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.

How do you alert a variable in JavaScript?

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!".


1 Answers

$(".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." ); 
like image 55
Adam Sills Avatar answered Oct 21 '22 21:10

Adam Sills