jQuery support “:invalid” selector

Using querySelectorAll as suggested by @JanDvorak (and his answer should be accepted for thinking of that), you can write your own expression, making .is(‘:invalid’) valid ? jQuery.extend(jQuery.expr[‘:’], { invalid : function(elem, index, match){ var invalids = document.querySelectorAll(‘:invalid’), result = false, len = invalids.length; if (len) { for (var i=0; i<len; i++) { if (elem === … Read more

Target elements by class prefix

It is called the Attribute Starts With Selector. My example sets a red text color on the elements: $(‘[class^=”tab”]’).css(‘color’, ‘red’); jsFiddle Demo Please note that if the elements have more than one class and the other precedes the one with tab inside (class=”nyedva tab231891230″) the element won’t be selected by this selector. If you want … Read more

JQuery data selector not updating with .data

jQuery .data() is initially populated with values from the data- attributes, but setting it only stores the associated new value in memory. It doesn’t change the attribute in the DOM. To change the attribute, you have to use: $(‘#one, #three’).attr(‘data-test’, ‘changed’); The docs are at http://api.jquery.com/jQuery.data/

jquery, find next element by class

In this case you need to go up to the <tr> then use .next(), like this: $(obj).closest(‘tr’).next().find(‘.class’); Or if there may be rows in-between without the .class inside, you can use .nextAll(), like this: $(obj).closest(‘tr’).nextAll(‘:has(.class):first’).find(‘.class’);

First word selector

Replacing HTML will result in event handlers being unbound and replacing the entire text for an element will result in HTML markup being lost. The best approach leaves any HTML untouched, manipulating only the first text node of the matching element. To get that text node, you can use .contents() and .filter(): function wrapFirstWord () … Read more