Thursday, March 1, 2012

Useful jQuery Tips

Check if a checkbox is checked:
if($('#checkbox').is(':checked')) ...

Check if a select option is selected:
if($('#select option:selected').length()) ...

Get the selected radio value:

Get all inputs with a classname begins with rescheck:
    function() {

Jump to ( Scroll To ) an element:
$('html, body').animate({ scrollTop: $("#some_element").offset().top }, 500);

Checking to see if there is an attribute on an element:
var attr = $(this).attr('name');
if (typeof attr !== 'undefined' && attr !== false) {}

Clear selection on select:
$("#my_select option:selected").removeAttr("selected");

Ajax request and putting the result array into a select:

  $.post("/url", function(data) {
    var selected = '';
    $.each(data, function(key, data) {

No comments:

Post a Comment