HTML DIV overflow and scroll
Sometimes, theoverflow-y:scroll
is not working.$('#div_scroll').css('overflow-y', 'auto')
Simply because the height
property is missing.$('#div_scroll').css('height', '200px')
Datepicker
Configure datepicker: make sure the right jQuery libs have been included.
Show calendar image only with a hidden input field.<input type="hidden" id="dp" />
$("#dp").datepicker({ |
Show both date input and image fields. The datepicker is binding to the input field. Then, when clicking the image, it also trigger the popup of same datepicker.<input type="text" id="date" >
<div>
<img id="date_img" src="../images/calendar.png”>
</div>
$("#date").datepicker({ |
Possible conflict with bootstrap
: when it comes with <div class="input-group date" data-provide="datepicker">
in HTML, the datepicker does not popup.
Get URL Parameters
<script type="text/javascript"> |
This is a JavaScript
implementation of PHP’s $_GET
functionality. It uses a regular expression to keep the code to a minimum. Here is a simple example of how to use it:
// this code would print "hello world" with http://someurl?var1=hello&var2=world |
// get the src parameter and split it down to the search query string |
Two Digits Hours and Minutes
function currentFormatTime(){ |
Format Date to MM/DD/YY
NOTE:
- Consider the case with a single digit in month and day
- Consider to slice the year to two digits.
getYear()
returns [year]-1900. E.g., 2016 - 1900 = 116.
function formatDate(date) { |
Populate HTML Table Dynamically
<div> |
NOTE:
$("#tableBody").empty()
clear the all children html elements inside#tableBody
$("#tableBody").remove()
removes all including#tableBody
itself.
$("#tableBody").empty(); |
Treat String like Variable Name
User eval
(may have some problem…).
Here, the #tableBody
shows content based on the option being selected in a dropdown list #select
. Suppose variable varName
has corresponding html table content.$('#select').on('change', function () {
$('#tableBody').empty();
var varName = $( "#select option:selected" ).val();
eval("$('#tableBody').append(" + varName + ")");
})
Another method, if varName
has been defined as global variable. Call it by window[varName]
.$('#tableBody').append(window[varName]);