jQuery Grab Bag – Whole bunch of jQuery Functionality

You could look at this post as a self serving block that I will use to save stuff I don’t want to remember later.

Or you could see it as a knowledge transfer that you the reader can learn from because I am a generous and giving tool.

Whatever, I really don’t care. I won’t sleep any differently. I just don’t feel like making 1000 posts of jquery stupidity.

I’ll add more as I come across them.


How To Check a CheckBox

  jQuery('#CheckBoxId').attr('checked', false);

How To Know if a Checkbox is Checked


How To Find a Bunch of Like Named Checkboxes that are Checked


Drop Down Lists

How to Add an Item/Option to a Drop Down List


Odd Note: Apparently jquery is smart enough to set the attributes on the option AND close the option with </option>

How to Remove an Item/Option from a Drop Down List

  jQuery('#DropDownListId option[value=\'3\']').remove();

How to Sort a Drop Down List by Option Text

  var sortedList = jQuery('#someDropDownList option').sort(
    function (first, second) {
      return first.text == second.text ? 0 : first.text < second.text ? -1 : 1;



How to Filter Out an Element in a List



  //Uncheck all id like someId_ and check only where id = someId_1
  var someElementList = someElement.children('[id*=someId_]');
  someElementList.attr('checked', false);
  someElementList.filter('[id=someId_1]').attr('checked', true);

How To Find an Element Based on a Like Name/Using Wildcards


How To Know if a Something is Hidden


Possible Use:

 function showOrHide(element) {
    if(jQuery(element).is(':hidden')) {
    else {

How to Disable an Input/Select

  jQuery('#DropDownListId').attr('disabled', 'disabled');

How to Enable an Input/Select


How to Know if an Element Exists

  jQuery('#ElementId').length > 0

Possible use:

  function elementExists(elementId) {
    return jQuery(elementId).length > 0;


How To Remove the First Character from a String

  someString.substring(1, someString.length)


How to Add a Row to a Table

  jQuery('#TableId > tbody:last').append('<tr>...</tr>')

How to Remove a Table Row

  jQuery('#TableId > tbody:last').children(someSortOfRowId).remove();


How to Post With a Link

  function postToUrl(path, params)
    var method = "post"; 

    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    for(var key in params)
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);



<a href="javascript:postToUrl('/SomeController/SomeAction/', { 'id', '1' })">link</a>

One thought on “jQuery Grab Bag – Whole bunch of jQuery Functionality”

  1. You guys just made my day! This site is great because it’s informative and humorous. After a while of reading so many dry posts about MVC examples, it’s nice to see some that are funny too. If you ever need any posts or examples of how to connect up your controllers to SharePoint sites or TFS projects, please feel free to let me know. Thanks and keep up the great work! 🙂

Comments are closed.