I am building a WebWorks app that starts with a login form and if login is successful a second page with the id='map' is supposed to be shown. I tried using $.mobile.changePage to display the page but it only reloads the login page. Why is't it loading the second page?
I stripped out all the login validation code to simplify things so I could figure out why the changePage isn't working.
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<link rel="stylesheet" href="lib/BlackBerry-JQM-all-1.0.0.css" />
<script src="lib/BlackBerry-JQM-all-1.0.0.js"></script>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBHGb5Si_2oXtOLCo_IzRIJPtrKkhyFPsU&sensor=false"></script>
</head>
<body>
<div data-role="page" id="login">
<div data-role="header">
<h1>TCOB - Login</h1>
</div>
<!-- /header -->
<div data-role="content">
<div class="BB10Container">
<form method="post">
<label for="username">Username</label>
<input type="text" name="user-input" id="username" placeholder="Username"/>
<label for="basic">Password</label>
<input type="password" name="pass-input" id="password" placeholder="Password"/>
<input type="submit" data-role="button" data-inline="true" data-icon="check" value="Submit" id="submit">
</form>
</div>
</div>
<!-- /content -->
<div data-role="footer" data-position="fixed">
</div>
</div>
<div data-role="page" id="map" >
<div data-role="header">
<h1>TCoB</h1>
</div>
<div data-role="content">
</div>
<div data-role="footer" data-position="fixed">
</div>
</div>
</div>
<script>
$(document).bind("mobileinit", function() {
$.mobile.page.prototype.options.backBtnText = "Zurück";
});
$('#username').keyup(function(){
$.get("http://www.hedonsoft.com/tcob/php/check_user.php",{username: $("#username").val()},function(data){
if(data == true){
$('#username').css("background-color","#00FFFF").css("color","#000000");
}else{
$('#username').css("background-color","#000000").css("color","#FFFFFF");
}
});
});
$('#submit').click(function(){
$.mobile.changePage("#map");
});
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
}
function getLocation(){
}
</script>
</body>
</html>
The problem is that you are both using a custom click handler and using a <form> to submit the form.
The custom click handler will navigate to #map and you can actually see that page flash up very briefly, but since your form has no action attribute, it will redirect to the same page – which is the login page, causing a second navigation and thus resulting in the weird behavior you are experiencing.
See this fiddle without a form to see that it works.
However, note that $.mobile.changePage is marked as deprecated as of 1.4.0 RC1.
Related
I like to use jQ Mobile Autocomplete https://github.com/commadelimited/autoComplete.js. But when I copy the example of jQM from http://andymatthews.net/code/autocomplete/local_complex.html to local server i always get the error: Uncaught TypeError: $(...).autocomplete is not a function. Here is the code i tryed:
<!DOCTYPE html>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="jqm.autoComplete-1.5.2-min.js"></script>
<script src="code.js"></script>
<div data-role="page" id="mainPage">
<div data-role="header">
<h1>jQM Autocomplete</h1>
<div>
</div>
</div>
<div data-role="content">
<h3>Local Complex Data</h3>
<p>
In this example autoComplete returns an array of objects from a local variable, each with a label and a value key.
</p>
<p>
<input type="text" id="searchField" placeholder="Categories">
<ul id="suggestions" data-role="listview" data-inset="true"></ul>
</p>
<p>
Download the code
</p>
</div>
</div>
<script>
$("#mainPage").bind("pageshow", function(e) {
autocompleteData = $.parseJSON('[{"value":"1.0","label":"Alabama"},{"value":"2.0","label":"Alaska"},{"value":"3.0","label":"American Samoa"},{"value":"4.0","label":"Arizona"},{"value":"5.0","label":"Arkansas"},{"value":"6.0","label":"California"},{"value":"7.0","label":"Colorado"},{"value":"8.0","label":"Connecticut"},{"value":"9.0","label":"Delaware"},{"value":"10.0","label":"District of Columbia"},{"value":"11.0","label":"Florida"},{"value":"12.0","label":"Georgia"},{"value":"13.0","label":"Guam"},{"value":"14.0","label":"Hawaii"},{"value":"15.0","label":"Idaho"},{"value":"16.0","label":"Illinois"},{"value":"17.0","label":"Indiana"},{"value":"18.0","label":"Iowa"},{"value":"19.0","label":"Kansas"},{"value":"20.0","label":"Kentucky"}, {"value":"21.0","label":"Louisiana"}, {"value":"22.0","label":"Maine"},{"value":"23.0","label":"Maryland"},{"value":"24.0","label":"Massachusetts"},{"value":"25.0","label":"Michigan"},{"value":"26.0","label":"Minnesota"},{"value":"27.0","label":"Mississippi"},{"value":"28.0","label":"Missouri"},{"value":"29.0","label":"Montana"},{"value":"30.0","label":"Nebraska"},{"value":"31.0","label":"Nevada"},{"value":"32.0","label":"New Hampshire"},{"value":"33.0","label":"New Jersey"},{"value":"34.0","label":"New Mexico"},{"value":"35.0","label":"New York"},{"value":"36.0","label":"North Carolina"},{"value":"37.0","label":"North Dakota"},{"value":"38.0","label":"Northern Marianas Islands"},{"value":"39.0","label":"Ohio"},{"value":"40.0","label":"Oklahoma"},{"value":"41.0","label":"Oregon"},{"value":"42.0","label":"Pennsylvania"},{"value":"43.0","label":"Puerto Rico"},{"value":"44.0","label":"Rhode Island"},{"value":"45.0","label":"South Carolina"},{"value":"46.0","label":"South Dakota"},{"value":"47.0","label":"Tennessee"},{"value":"48.0","label":"Texas"},{"value":"49.0","label":"Utah"},{"value":"50.0","label":"Vermont"},{"value":"52.0","label":"Virgin Islands"},{"value":"51.0","label":"Virginia"},{"value":"53.0","label":"Washington"},{"value":"54.0","label":"West Virginia"},{"value":"55.0","label":"Wisconsin"},{"value":"56.0","label":"Wyoming"}]');
$("#searchField").autocomplete({
target: $('#suggestions'),
source: autocompleteData,
link: 'target.html?term=',
minLength: 1
});
});
</script>
I'm new to this jQM stuff, as well as AJAX.
I have a site that keeps a static header and footer, and replaces #mainContent div with external .html/.php pages.
What I am finding is that when I click one of the nav-bar tabs (included in the header), and the #mainContent is replaced with another page, the jQuery Mobile-styling (of buttons, drop-down menus, etc) does not load right away.
Initially the default-style of buttons appears, then (if AJAX loads) a second later the page does a 'refresh-type blink', and the buttons are replaced with the jQM styled-versions.
Occasionally I get stuck with the AJAX 'loading circle', and the buttons retain their original style until the 'nav-bar link' is pressed again.
I know there's a perfectly good reason for this.
Research indicated that using "$(document).ready(function() { .... });" is not ideal for jQM. I replaced this in my navigation-script with "$(document).bind('pageinit', function() { .... });", which didn't really make a difference (though the navbuttons still work).
Here is my basic script initialization for my index.php
<!DOCTYPE html>
<head>
<title>NoteVote</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<link rel="stylesheet" href="./NV_home.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<div data-role="page" id="noteVote">
<!-- HEADER -->
<div data-role="header" align="middle" class="header">
<img src="images/banner_post_it.png" align="middle" alt="Banner Image" height="100" width="250"/>
<!-- NAVBAR -->
<div data-role="navbar" data-grid="c" id="navBar">
<ul>
<li><a class="ui-btn" id="coursesButton">Courses</a></li>
<li><a class="ui-btn" id="searchButton">Search</a></li>
<li><a class="ui-btn" id="submitButton">Submit</a></li>
<li><a class="ui-btn" id="accountButton">Account</a></li>
</ul>
</div>
<!-- /NAVBAR -->
</div>
<!-- /HEADER -->
<!--
This is the MAIN This is where the contents will be replaced
-->
<div data-role="content" class="ui-content" id="mainContent">
<div class="main">
<p/>
content here.\
</div>
</div>
<!-- /MAIN -->
<!-- FOOTER -->
<div data-role="footer" class="footer" id="footer">
<?php
require_once('../account.php');
if ($account == "_")
{
echo "Not logged in";
} else {
echo "Logged in as " . $account;
}
?>
</div>
<!-- /FOOTER -->
</div>
<!-- /INDEX -->
<script src="./scripts/navScript.js"></script>
</body>
</html>
My navScript.js:
$(document).bind('pageinit', function() {
$("#coursesButton").on("click", function(e) {
//e.preventDefault();
//alert('courses');
$("#mainContent").load("./pages/courses.html");
});
$("#searchButton").on("click", function(e) {
//e.preventDefault();
//alert('search');
$("#mainContent").load("./pages/search.html");
});
$("#submitButton").on("click", function(e) {
//e.preventDefault();
//alert('submit');
$("#mainContent").load("./pages/submit.html");
});
$("#accountButton").on("click", function(e) {
//e.preventDefault();
//alert('account');
$("#mainContent").load("./pages/accountPage.php");
});
});
And then here is one of my external pages loaded. This is where the button-styling doesn't load properly... (search.html):
<!DOCTYPE html>
<html>
<head>
<title>NoteVote</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<link rel="stylesheet" href="./NV_home.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<div data-role="content" class="ui-content" id="mainContent">
<div class="wrap">
<div class="main">
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<form method="POST" action="./search_result.php">
<legend><h3>Course:</h3></legend>
<select name="course" id="customSelect">
<option value="*">All</option>
<option value="COMM2216">COMM-2216</option>
<option value="COMP2121">COMP-2121</option>
<option value="COMP2510">COMP-2510</option>
<option value="COMP2526">COMP-2526</option>
<option value="COMP2714">COMP-2714</option>
<option value="COMP2721">COMP-2721</option>
</select>
</fieldset>
<p/>
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<legend><h4>Type:</h4></legend>
<input type="radio" name="type" value="lec" id="lec"/>
<label for="lec">Lecture</label>
<input type="radio" name="type" value="lab" id="lab">
<label for="lab">Lab</label>
<input type="radio" name="type" value="*" id="both" checked="checked">
<label for="both">Both</label>
<p/>
<input type="submit" value="Go">
</fieldset>
</form>
</div>
</div>
</div>
<script src="./scripts/searchGo.js"></script>
</body>
</html>
If you could give me a pointer as to why it takes a second to 'refresh' before the jQuery-Mobile style over-rides that of the standard HTML5, I'd greatly appreciate it.
I have a feeling it is due to the scripts/styles being loaded twice (ie in the index.php and the search.html ), but if I do not load them in each page, then the buttons do not get stylized...
Though not really affecting basic functionality, it does give the web-app the appearance of really lagging.
Cheers.
The problem is you are not initializing the content you are loading via Ajax. When you load external data dynamically, you need to manually initialize any jQuery Mobile's "widget".
All you need is to call .enhanceWithin() on $("#mainContent") after data is successfully loaded. Hence, you need to use .load()'s callback function to initialize those elements.
$(document).on('pagecreate', "#noteVote", function () {
$("#coursesButton").on("click", function (e) {
e.preventDefault();
$("#mainContent").load("URL", function () {
$(this).enhanceWithin();
});
});
});
Demo (1) - Code
(1) Click "Courses" or "Search" buttons
I keep running into this issue. This is my first phonegap application, and really my first time utilizing jQuery and jQuery mobile.
I've created a simple app that I just want to get a "Tracking Number" from the user, then submit it to a server side script on a different server, and show the results on the same page.
I've tried lots of different ways and contiune to run into the issue of everything works, but only if you submit the form once (it seems to reload) and then submit it again.
main.js:
var app = {
initialize: function() {
$('#tracking-form').on('submit', function(e){
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
app.searchByTracking();
return false;
});
},
searchByTracking: function() {
var formData = $("#tracking-form").serialize();
$.ajax({
type: "POST",
url: "http://newepicweb.com/bodypros/search.php",
cache: false,
data: formData,
success: function (result) {
$("#search-results").html(result);
},
error: function (request,error) {
console.log("Error " + error);
}
});
}
};
app.initialize();
search.html
<html>
<head>
<link rel="stylesheet" href="css/jquery.mobile-1.4.1.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!-- Start of first page: #one -->
<div data-role="page" id="search" data-theme="b">
<div data-role="header">
<h1>Search by Tracking Number</h1>
</div><!-- /header -->
<div data-role="content" >
<h2>Instructions</h2>
<p>Click below to enter your tracking number, then press search to view the status of your vehicle.</p>
<div id="form">
<form id="tracking-form" data-ajax='false'>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Tracking Number:</label>
<input type="text" name="tracking-number" id="tracking-number" value="" placeholder="Tracking Number" data-theme='a' />
</div>
<input type='submit' value='Search' />
</form>
</div>
<div id="search-results">
</div>
<p> </p>
<p>Back to Menu</p>
</div><!-- /content -->
</div><!-- /page one -->
<!-- Start of second page: #two -->
<div data-role="page" id="results" data-theme="a">
<div data-role="header">
<h1>Body Pro's</h1>
</div><!-- /header -->
<div data-role="content" data-theme="a">
<h2>Vehicle Status</h2>
<p>Search Again</p>
</div><!-- /content -->
</div><!-- /page two -->
<script src="lib/jquery-1.11.0.min.js"></script>
<script src="lib/jquery.mobile-1.4.1.js"></script>
<script src="lib/handlebars-v1.3.0.js"></script>
<script src="js/storage/memory-store.js"></script>
<script src="js/main.js"></script>
</body>
</html>
Basically, I'm trying to get input from the user, fetch the content using the input, then display the input to the user...
Any suggestions or info will help. Thanks!
-- Also, maybe it has something with..
$('#tracking-form').on('submit', function(e){ } )
It doesn't seem to register until the form was submitted once. I added console.log() and it only fired after the second time i pushed it.
You are submitting the whole form. So it's reloading the whole dom which you dont want.
So you should use simple button and use Onclick function.
Like this-
<input type='button' value='Search' onclick="app.searchByTracking()" />
Instead of submitting the form, change this:
<input type='submit' value='Search' />
to:
<input type='button' value='Search' onclick="app.searchByTracking()" />
Since you are staying on the same page, you don't actually want to submit the form, you just want to call the function that collects the data from the form and do your own submit from the searchByTracking function.
I am trying to add google maps for my form, so after they enter the address they can view map and after that maps latitude and longitude submitted to the database. So far I couldn't implement it. I tried it on jsfiddle and it worked. But when i try to add to the page it not working.
http://jsfiddle.net/pborreli/pJgyu/
Here is the full page.
<!DOCTYPE html>
<htmllang-"en">
<head>
<meta charset="utf-8">
<title>My First Guide</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="css/prettify.css" rel="stylesheet">
<!--<link href="css/docs.css" rel="stylesheet">-->
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$("#address").change(function() {
var geocoder = new google.maps.Geocoder();
var add = $("#address").val();
geocoder.geocode( { 'address': add}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var map;
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(latitude, longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),
myOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
};
});
</script>
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">My First Guide</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active">Home</li>
<li>Write a review</li>
<li>Talk</li>
<li>Events</li>
<li>
<form class="navbar-search pull-left">
<!--You can put class="search-query" too.-->
<input type="text" class=".navbar-search" placeholder="Search">
</form>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!-- div container -->
</div><!-- div navbar-inner -->
</div><!-- navbar navbar-fixed-top -->
<div class="container">
<form class="form-horizontal">
<fieldset>
<legend>Submit Business Place</legend>
<div class="control-group">
<label class="control-label" for="input01">Business Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="input01">
<p class="help-block">Please specify the name of business.(May
be it is a brand name)</p><br />
</div>
<div class="control-group">
<label class="control-label" for="input01">Address</label>
<div class="controls">
<input type="text" class="input-xlarge" id="ad">
<p class="help-block">To use lines please specify
‹br/› tag.</p><br/>
<div id="map"></div>
</div>
<div class="control-group">
<label class="control-label" for="textarea">Description</label>
<div class="controls">
<textarea class="input-xlarge" id="textarea" rows="10"></textarea>
</div>
</div>
<label class="control-label" for="input01">Categories</label>
<div class="controls">
<input type="text" class="input-xlarge" id="input01">
<p class="help-block">Use comma as a separator.</p><br />
</div>
</fieldset>
</form>
</div>
<script src="js/jquery.js"></script>
<script src="js/bootstrap-transition.js"></script>
<script src="js/bootstrap-alert.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="js/bootstrap-dropdown.js"></script>
<script src="js/bootstrap-scrollspy.js"></script>
<script src="js/bootstrap-tab.js"></script>
<script src="js/bootstrap-tooltip.js"></script>
<script src="js/bootstrap-popover.js"></script>
<script src="js/bootstrap-button.js"></script>
<script src="js/bootstrap-collapse.js"></script>
<script src="js/bootstrap-carousel.js"></script>
<script src="js/bootstrap-typeahead.js"></script>
</body>
</html>
But here is javascript stuff.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
$("#address").change(function() {
var geocoder = new google.maps.Geocoder();
var add = $("#address").val();
geocoder.geocode( { 'address': add}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var map;
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(latitude, longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),
myOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
};
});
</script>
And here is the div where i add my map.
<div class="control-group">
<label class="control-label" for="input01">Address</label>
<div class="controls">
<input type="text" class="input-xlarge" id="ad">
<p class="help-block">To use lines please specify
‹br/› tag.</p><br/>
<div id="map"></div>
</div>
I've done a quick scan of your code and there seem to be some basic coding problems:
You appear to create your map in an intialize function, but your initialize function appears to be embedded within the larger .change() callback function; I do not see how your map is ever going to be displayed.
Your JavaScript code is focused on a jQuery search for an element with the id: address, but there does not appear to be an element with that id in your markup.
The label you define that contains the text Address says that it is a label for: input01, but you have 2 distinct elements in your markup that have been assigned the id: input01.
There are multiple labels that have been marked as being the label for: input01.
All of the script tags you have defined at the bottom of your file are missing the type attribute.
I think you have too many basic coding errors and it looks like you may have possibly garbled the code during the process of submitting it for review? It's hard to tell, but I hope my feedback is helpful and will help you to get closer to your goal.
I've been asked to prototype a login box for a project, with the goal of emulating how an AJAX-y login box would.
Idea is:
User types in username/password (any; again, this isn't hooked up to any DBs or anything yet) and hits enter
Throbber shows up for 3 seconds.
User info appears.
I've tried doing this with jQuery as per the below; anyone have an idea what I'm doing wrong? Many thanks!
<html>
<head>
<link href="c/main.css" media="screen" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<!--[if lte ie7]>
#header #logo {margin-right: 100px;}
<!-[endif]-->
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#login-form').submit(function(){
jQuery('#login-form > *').hide();
jQuery('#throbber').show().delay(300).hide();
jQuery('#logged-in').show();
return false;
});
});
</script>
</head>
<body>
<div id="wrapper">
<div id="utilities">VolunteerAbout Us<input type="text" /></div>
<div id="header">
<img src="i/logo.png" id="logo" />
<div id="pnav-wrapper">
<ul id="pnav">
<li>Upgrade Your<br /><span>Skills</span></li>
<li>Browse<br /><span>Events</span></li>
<li>Browse<br /><span>Jobs</span></li>
</ul>
<div id="login">
<form action="#" method="get" id="login-form">
Username: <input id="username" type="text" /><br />
Password: <input id="password" type="password" />
<input type="submit" style="visibility: hidden;">
</form>
<img src="i/throbber.gif" style="display: none;" id="throbber">
<p id="logged-in" style="display: none;"><strong>The Admin</strong><br />
Administrator
</p>
</div>
</div>
</div>
<div id="content"></div>
</div>
</body>
</html>
The delay() only affects the queue for #throbber (and 300 is 0.3 second).
Instead, use the callback of .hide() to show #logged-in after #throbber has been hidden:
jQuery('#login-form').submit(function() {
jQuery('#login-form > *').hide();
jQuery('#throbber').show().delay(3000).hide(function() {
jQuery('#logged-in').show();
});
return false;
});
(demo)
You need to change delay to 3000, make the whole login-form hide rather than just the child elements, and this part is key... put the logged in showing code inside a callback function to be executed after the throbber is hidden... like this:
jQuery('#login-form').submit(function(){
jQuery('#login-form').hide();
jQuery('#throbber').show().delay(3000).hide(function(){
jQuery('#logged-in').show();
});
return false;
});
Try this: http://jsfiddle.net/dbhCe/
jQuery(document).ready(function(){
jQuery('#login-form').submit(function(){
jQuery('#login-form').hide();
jQuery('#throbber').show();
window.setTimeout( function() {
jQuery("#throbber").hide();
jQuery('#logged-in').show();
}, 3000);
return false;
});
});
Here is a demo
http://jsfiddle.net/6UwDn/2/