Prevent Anchor Links from Loading

Prevent Anchor Links from Loading

$("a").on("click", function(e){ e.preventDefault(); });

javascript-jquery-snippets - 4 years ago 1 minute read

JQuery Check if Element Exists

JQuery Check if Element Exists

if ($('#myElement').length > 0) { // it exists }

javascript-jquery-snippets - 4 years ago 1 minute read

Check for Empty Elements

Check for Empty Elements

if($('#myDiv').is(':empty')) { // do something }

javascript-jquery-snippets - 4 years ago 1 minute read

JQuery Adding/Removing Class on Hover

JQuery Adding/Removing Class on Hover

$('#element').hover( function(){ $(this).addClass('hover') }, function(){ $(this).removeClass('hover') } )

javascript-jquery-snippets - 4 years ago 1 minute read

Google Webfonts and performance fix

Google Webfonts and performance fix

WebFontConfig = { google: { families: [ 'PT+Sans:400,400italic:latin', 'Ubuntu:300,400,500:latin' ] } }; var cb = function() { var wf =...

javascript-jquery-snippets - 5 years ago 1 minute read

Checking if an element is hidden

Checking if an element is hidden

You can use the hidden,visible selector: The hidden selector: // Matches all elements that are hidden $('#myDiv').is(':hidden') The visible selector:...

javascript-jquery-snippets - 5 years ago 1 minute read

Capitalize the first letter of a string in javascript

Capitalize the first letter of a string in javascript

var capitalizeMe = "capitalize the first letter of a string in javascript"; var capitalized = capitalizeMe[0].toUpperCase() + capitalizeMe.substring(1); console.log(capitalized); //...

javascript-jquery-snippets - 5 years ago 1 minute read

Checking a checkbox with jQuery?

Checking a checkbox with jQuery?

$(".myCheckbox").attr('checked', true); // Deprecated $(".myCheckbox").prop('checked', true); Check if the checkbox is checked There are several ways to get to work...

javascript-jquery-snippets - 5 years ago 1 minute read

Redirect a page using jQuery?

Redirect a page using jQuery?

var url = 'http://www.arjunphp.com/'; $(location).attr('href',url);

javascript-jquery-snippets - 5 years ago 1 minute read

Detect Current Mouse Coordinates using JQuery

Detect Current Mouse Coordinates using JQuery

Here is the simple JQuery script snippet for detecting current mouse coordinates using JQuery function. $(document).mousemove(function(e){ console.log("X = " +...

javascript-jquery-snippets - 6 years ago 1 minute read