Browse Tag

tip

jQuery using $.on to call newly added elements

More than a year ago, I had written a blog about how to bind events to newly added elements using jQuery.

The scenario can be found here: http://blog.kongnir.com/2012/02/08/jquery-function-not-binding-to-newly-added-dom-elements/

In my previous solution, I had used $.live() in place of $.change(). However, as noted by a commenter in that blog, as of time of writing, $.live() is deprecated.

Instead, we should now use $.on() if you need to capture events of newly added elements.

For example, in normal circumstance, we would do this:

$(".existing-button").click(function() {
    alert("This will work if button already exist on load");
});

However, if you add new elements to the document using AJAX, then the above will not work. That button doesn’t exist.

In both circumstances, this will work:

$(document).on("click",".new-button", function() {
    alert("This will work even if element is newly added");
});

If you notice, the syntax is quite different. The element to call on is the containing element, not the element that the event is called. So let’s say “.new-button” is contained within “#main”, then the following should work too.

$("#main").on("click",".new-button", function() {
    alert("This will work even if element is newly added"); 
});

Reference: http://api.jquery.com/on/

Prepaid SIM card in Switzerland and Germany

Travel Tip to Switzerland and Germany

Just came back from Zurich-Munich trip. I’ve the habit of reading online news (via Flipboard) and playing mobile games that require internet connection during travel. Especially if I need to travel a lot locally from places to places. So whenever I visit a country, I’ll always look for their prepaid SIM card with data connection options.

For Switzerland, it seems like an easy option, because Swisscom is everywhere, somewhat like our Singtel in Singapore. I had signed up for their NATEL easy smart prepaid SIM card. It costs CHF19.90, including CHF20 credit. They charge CHF2 per day for unlimited data access. This is the default option so no need to activate data plan. Essentially the card can last up to 10 days of unlimited data access. My friend and I used Whatsapp to communicate so we didn’t need to call each other at all. Like I’d said, Swisscom is everywhere. You can find their store in Zurich airport and the central train station. The staffs were friendly but it took them about 30 to 45 mins to help you register your card, allow some time for this before you plan anything else. Passport or identity card is required for registration. The connection was generally good, even in areas such as Lauterbrunnen and Jungfraujoch. By the way, most stores in Zurich open at 8am, so if you arrive early, you may need to wait till then. They provide nano SIM card, so remember to ask for it if you’re using iPhone 5. The settings are done automatically when you insert the card.

As for Germany, it took me quite a while to understand the “big” and “small” providers. If you read up the internet, you’ll see a long list of mobile plan providers in Germany. In short, the smaller providers tag on to the bigger providers’ network and provide services to their own customers.

After a long search, I found in a forum this Blau.de which offers a cheaper option and it’s available in an electronic shop in the Munich airport. It tags on to the E-plus network. Unfortunately, they don’t have an English website, but fortunately we have Google Chrome to help do the translation. So I got this Blau.de 9-cent Tarif plan for Germany. You can get it from Munich airport Electronic store or any E-Plus stores. It costs 20 Euro (includes 10 Euro credit). You can ask the staff to help activate the 9.90 Euro plan for 1GB data for 1 month (the staff in the Electronic store told me it’s actually unlimited, but first 1GB at high speed). It will use up all the credits you have but again, my friend and I used Whatsapp to communicate so we didn’t need any credit for phone calls. If you need nano SIM card, the staff at the Munich airport electronic shop will help to cut it for you. Make sure you ask the staff to set up the data internet settings, it can be quite complicated. And to be very sure, remember to update and backup your iPhone before you travel. There was this girl with iPhone 4 or 4S at the counter when I was there. She couldn’t connect to the internet because she was using a very old version of iOS, which didn’t support Germany network. The overall data connection was generally good but patchy at some places. I had experienced good and poor connection just within 2 streets. But the network was fine in most popular attractions.

I hope this is useful for people who are planning to travel to Switzerland or Germany.