/ Published in: jQuery
When you want to test to see if jQuery is working, plus two different examples on how to write jQuery so that it will not conflict with other JavaScript based libraries. Then I show the shorthand way of writing jQuery which I would not get into the habit of. It's not worth the headaches you'll run into when working with a CMS or legacy apps.
Expand |
Embed | Plain Text
<!-- Example 1: Non-Conflicting jQuery --> jQuery(document).ready(function(){ //option 1: add the jqtest ID in your html to the link/a-tag of your choice and then click it for an alert. jQuery("#jqtest").click( function() { alert("jQuery is working!"); }); //option 2: send a message to the console but the browser must support console.log(). console.log("jQuery is working!"); }); <!-- ******************************************************* --> <!-- Example 2: Non-Conflicting jQuery --> jQuery(document).ready(function($) { //option 1: add the jqtest ID in your html to the link/a-tag of your choice and then click it for an alert $("#jqtest").click( function() { alert("jQuery is working!"); }); //option 2: send a message to the console but the browser must support console.log(). console.log("jQuery is working!"); }); <!-- ******************************************************* --> <!-- This is the shorthand way to write jQuery although it might conflict with other libraries. This is just to show the difference. --> $(document).ready(function(){ $("#jqtest").click( function() { alert("jQuery might now conflict with other libraries!"); }); });
You need to login to post a comment.
