Showing posts from April, 2013

Disable right click with jquery

jQuery makes it easy to disable the right click with just few lines of codes. bind contextmenu to the document and return false. however, this will disable the right click on entire document.
$(function(){ //document.ready function $(document).on("contextmenu",function(e){ alert('right click disabled'); return false; }); }); to disable right click in certain elements, you can give it a class/id and use respective selector.
right click disableright clickright clickno right clicktry it in fiddle

jquery attr() vs prop() (difference)

according to the docs

Get the value of an attribute for the first element in the set of matched elements.

Get the value of a property for the first element in the set of matched elements.
Before jQuery 1.6 , the attr() method sometimes took property values into account when retrieving some attributes, which caused in inconsistent behavior. And thus, the prop() method was introduced. As of jQuery 1.6. , the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

What actually is Attributes?
Attributes carry additional information about an HTML element and come in name=”value” pairs. You can set an attribute for HTML element and define it while writing the source code.

simple example can be:
here, "type","value", "id" are attributes of the input elements.

What is Property?
Property is a representation of an attribute in the HTML DOM tree. once the browser parse you…