X

LATEST #JQUERY NEWS

5 Cool and Useful jQuery Tricks


1. Disable Right Click

The code snippet below disables right click on an entire page, but you can make it work on only particular page elements by changing the selector from document to something more specific.

   $(document).ready(function(){
		$(document).bind("contextmenu", function(e){
			return false;
		})
	})

2. Set a Timer
The following code snippet sets off an alert exactly 3 seconds after the page has loaded.

$(document).ready(function(){
		setTimeout(function(){
			alert("Surprise!");
		}, 3000);
	})

3. Browser Detection
jQuery can easily detect which browser a page is being viewed on, and can even be used to apply style or make changes to HTML elements depending on which browser is being used. The code below changes the padding on all p elements when the browser is Safari.

if($.browser.safari) $("p").css("padding", "1em");

4. Dynamically Alter Links
This one is particularly useful if you want to add target=”_blank” to all the links on a particular page without having to go through and do it manually.

$('a[@rel$='external']').click(function(){
  this.target = "_blank";
});

5. Check if Elements Exist
Avoid errors by writing code like this one below that checks if an element exists before it executes the action.

if ($("#someElement").length)
{ 
	//The DOM element exists
}

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...