Difference between jQuery attr() and prop()

By Nethru Limited (www.nethru.com)

jQuery

Starting from jQuery 1.6, they introduced the method prop(). According to the official document of jQuery, the reason they introduced this new method is due to inconsistent behavior when using attr() before jQuery 1.6.

Before jQuery 1.6, the attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.

Someone may ask when we have to use attr() and when to use prop(), this is how the official document said.

To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method.

That means they suggest us to use prop() when we are going to get the attributes when boolean result, like checked, disabled or selected.

Read more

Sharing: Online SVG editor (in JavaScript)

By Nethru Limited (www.nethru.com)

If you are searching for a free and simple SVG editor or viewer, the following may be a good choice, which I found on Google Code recently. (svg-edit)

It is open source, so you can download and use it for free. Besides, it has a demo here. So, you may use it as an online SVG editor.

svg-edit screenshot

Simple and easy-to-use UI


Read more

Transition event in MIUI systems

By Nethru Limited (www.nethru.com)

xiaomi logo

Recently fixed a bug related to the abnormal behaviour for transition event in MIUI systems. Let’s see the following code.

$("#mypage").one('webkitTransitionEnd', function() {
   // do something after transition event ends
});

This code works without any problems in most of the Android devices. But when I try this in the devices using MIUI, this code does not execute. After searching on Google and testing, I found that webkitTransitionEnd is not supported in MIUI devices, instead it uses transitionend event. So I changed the script to the following and it works.

$("#mypage").one('webkitTransitionEnd transitionend', function() {
   // do something after transition event ends
});

Notes (1) – Obtain URL information using JavaScript

By Nethru Limited (www.nethru.com)

Do you have a practice to jot down some notes for what you have studied or learnt when you are doing your works? I am going to share my notes to you here, hope that they are useful to you as well.
Let’s start from a simple but common one – obtain URL information using JavaScript.

Suppose you are coding in this URL:
http://www.nethru.hk:8080/demo/helloworld.php?user=guest#debug
If you put the following JavaScript codes to your page

<script type="text/javascript">
    document.write("location.href: "+location.href+"<br/>");
    document.write("location.protocol: "+location.protocol+"<br/>");
    document.write("location.hostname: "+location.hostname+"<br/>");
    document.write("location.host: "+location.host+"<br/>");
    document.write("location.port: "+location.port+"<br/>");
    document.write("location.pathname: "+location.pathname+"<br/>");
    document.write("location.search: "+location.search+"<br/>");
    document.write("location.hash: "+location.hash+"<br/>");
</script>

Your page will show:
location.href: http://www.nethru.hk:8080/demo/helloworld.php?user=guest#debug
location.protocol: http
location.hostname: www.nethru.hk
location.host: www.nethru.hk:8080
location.port: 8080
location.pathname: /demo/helloworld.php
location.search: ?user=guest
location.hash: #debug

Use Google App Engine to serve static files

By Nethru Limited (www.nethru.com)

Get a free website hosting using Google App Engine

free website hosting google app engine
Google App Engine (GAE) is a cloud computing platform for web applications. However, you can just use it to serve your static files, such as js, css, html, images, etc. Somebody may think that it is an overkill to use GAE for this purpose, but it is not a bad idea because the service is backed by Google’s data center. If you are looking for free static web hosting service, and you expect the traffic will not be very high (< 1GB per day), GAE may be your choice. Read more

1 2