Monday, April 29, 2013

jQuery - when to use attr() ?? when to use prop() ???

with effect from jQuery 1.6 a new method has been introduced to change or retrieve values of attributes (or properties).

So what is the big deal here you might ask. the problem is that new comers doesn't understand the difference between the attr() method which has been there and the new method prop() which introduced lately.

In a HTML element there is two kind of  things we can see.
  1. Attributes
  2. Properties
I will explain this by an example. Lets take following HTML input tag for an instance.

 <input id="q" value="" class="button-gray" name="_3_keywords" readonly>  

In the above example  id, value, name are belong to Attribute family while readonly is a property. So when to use attr() method or when to use prop() method is depend on whether you are dealing with an attribute or a property.

For example lets say you want to change the class attribute of above INPUT tag. Here you have to use  attr() method like below.

 $("#q").attr("class", "newclass")  

But lets say if you want to make the above INPUT tag readable (it is readonly originally according to the code above). So here you have to use prop() from  jQuery 1.6 onwards like below.

 $("#q").prop("readonly", false)  

Yeah you might noticed the change. Before jQuery 1.6 you have to use attr() method like below. 

 $("#q").attr("readonly", "readonly")  

But with new  prop() you can save life by just giving a boolean as the second attribute.

 


"ceylon" command throwing "UnsupportedClassVersionError" exception

When i was trying to install and configure classpath for Ceylon programming language to begin coding i was getting this error which does not describe it self.


 Exception in thread "main" java.lang.UnsupportedClassVersionError: com/redhat/ce  
 ylon/launcher/CeylonClassLoader : Unsupported major.minor version 51.0  
     at java.lang.ClassLoader.defineClass1(Native Method)  
     at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)  
     at java.lang.ClassLoader.defineClass(ClassLoader.java:615)  
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14  
 1)  
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)  
     at java.net.URLClassLoader.access$000(URLClassLoader.java:58)  
     at java.net.URLClassLoader$1.run(URLClassLoader.java:197)  
     at java.security.AccessController.doPrivileged(Native Method)  
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)  
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)  
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)  
     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)  
 Could not find the main class: com.redhat.ceylon.launcher.Launcher. Program will  
  exit.  

The mistake i did at the beginning seems to be avoid reading the "README.md" file in ceylon package. In there it clearly stated that "Ceylon execute on any Java 7 compatible JVM ... "

So the above error gives because of the incompatible JVM version. (as it says in the line "Unsupported major.minor version 51.0" ).

So to fix this what you need to do is simply install the JDK 7 and add it to the classpath, JAVA_HOME and JRE_HOME. That will fix this.

HAPPY CEYLON CODING !!!


Monday, April 22, 2013

tools.jar can not be found in JRE folder

I came across this error other day i was trying to configure ant in my new machine. The reason for this is that the relevant jar file is not in the <JRE location>lib folder but in <JDK location>lib folder.

The most simplest fix for this is to just copy the "tools.jar" file from the <JDK location>lib to  
<JRE location>lib folder.
 
Good luck.
:)