Select first TD in every row w/ jQuery

Use the :first-child pseudo class instead of :first. $(“#myTable tr td:first-child”).addClass(“black”); The :first pseudo class actually selects the first element that was returned in your list. For example, $(‘div span:first’) would return only the very first span under the first div that happened to be returned. The :first-child pseudo class selects the first element under …

Read more

Revert a jQuery draggable object back to its original container on out event of droppable

TESTED with jquery 1.11.3 & jquery-ui 1.11.4 DEMO: $(function() { $(“#draggable”).draggable({ revert : function(event, ui) { // on older version of jQuery use “draggable” // $(this).data(“draggable”) // on 2.x versions of jQuery use “ui-draggable” // $(this).data(“ui-draggable”) $(this).data(“uiDraggable”).originalPosition = { top : 0, left : 0 }; // return boolean return !event; // that evaluate …

Read more

jQuery UI – Draggable is not a function?

A common reason this occurs is if you don’t also load jqueryui after loading jquery. For example: <script src=”” type=”text/javascript”></script> <script src=”” type=”text/javascript”></script> EDIT. Replace the version number for each library with appropriate or latest values for jquery and jqueryui. If this doesn’t solve the issue, review suggestions in the many other answers.

jQuery add blank option to top of list and make selected to existing dropdown

This worked: $(“#theSelectId”).prepend(“<option value=”” selected=’selected’></option>”); Firebug Output: <select id=”theSelectId”> <option selected=”selected” value=””/> <option value=”volvo”>Volvo</option> <option value=”saab”>Saab</option> <option value=”mercedes”>Mercedes</option> <option value=”audi”>Audi</option> </select> You could also use .prependTo if you wanted to reverse the order: ​$(“<option>”, { value: ”, selected: true }).prependTo(“#theSelectId”);​​​​​​​​​​​

Last element in .each() set

each passes into your function index and element. Check index against the length of the set and you’re good to go: var set = $(‘.requiredText’); var length = set.length; set.each(function(index, element) { thisVal = $(this).val(); if(parseInt(thisVal) !== 0) { console.log(‘Valid Field: ‘ + thisVal); if (index === (length – 1)) { console.log(‘Last field, submit form …

Read more