JavaScript
Article
By Sam Deering

Different ways jQuery.Alert() can be used

By Sam Deering
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min
--ADVERTISEMENT--

what is .alert()

Sometimes you need to go back to basics and use the .alert() function is jQuery to see what the hell a variable is or check if your JavaScript is actually working at all?! 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 that contains text information displayed to the user.

How to use .alert()

//when the webpage is loaded
jQuery(document).ready(function($) {
	alert("js is working");
});

Other variations:

alert($('#test'));
// or
alert($('#test').get(0));
// also try
alert(document.getElementById('test'));

If the last one doesn’t work (it should alert ‘HTMLElement’, depending on the browser) then jQuery is not working, you might need to check your imports are correct or check for errors in your JavaScript files.

Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?