jQuery change class name

Using jQuery You can set the class (regardless of what it was) by using .attr(), like this: $(“#td_id”).attr(‘class’, ‘newClass’); If you want to add a class, use .addclass() instead, like this: $(“#td_id”).addClass(‘newClass’); Or a short way to swap classes using .toggleClass(): $(“#td_id”).toggleClass(‘change_me newClass’); Here’s the full list of jQuery methods specifically for the class attribute.

val() doesn’t trigger change() in jQuery

onchange only fires when the user types into the input and then the input loses focus. You can manually call the onchange event using after setting the value: $(“#mytext”).val( 777 ).change(); // someObject.onchange(); in standard JS Alternatively, you can trigger the event using: $(“#mytext”).val( 777 ).trigger(“change”);

What are queues in jQuery?

The uses of jQuery .queue() and .dequeue() Queues in jQuery are used for animations. You can use them for any purpose you like. They are an array of functions stored on a per element basis, using jQuery.data(). They are First-In-First-Out (FIFO). You can add a function to the queue by calling .queue(), and you remove … Read more

jQuery validation: change default error message

Add this code in a separate file/script included after the validation plugin to override the messages, edit at will 🙂 jQuery.extend(jQuery.validator.messages, { required: “This field is required.”, remote: “Please fix this field.”, email: “Please enter a valid email address.”, url: “Please enter a valid URL.”, date: “Please enter a valid date.”, dateISO: “Please enter a … Read more

Datatables: Cannot read property ‘mData’ of undefined

FYI dataTables requires a well formed table. It must contain <thead> and <tbody> tags, otherwise it throws this error. Also check to make sure all your rows including header row have the same number of columns. The following will throw error (no <thead> and <tbody> tags) <table id=”sample-table”> <tr> <th>title-1</th> <th>title-2</th> </tr> <tr> <td>data-1</td> <td>data-2</td> … Read more

Select2 doesn’t work when embedded in a bootstrap modal

Ok, I’ve got it to work. change <div id=”myModal” class=”modal hide fade” tabindex=”-1″ role=”dialog” aria-labelledby=”myModalLabel” aria-hidden=”true”> <div class=”modal-header”> <button type=”button” class=”close” data-dismiss=”modal” aria-hidden=”true”>×</button> <h3 id=”myModalLabel”>Panel</h3> </div> <div class=”modal-body” style=”max-height: 800px”> to <div id=”myModal” class=”modal hide fade” role=”dialog” aria-labelledby=”myModalLabel” aria-hidden=”true”> <div class=”modal-header”> <button type=”button” class=”close” data-dismiss=”modal” aria-hidden=”true”>×</button> <h3 id=”myModalLabel”>Panel</h3> </div> <div class=”modal-body” style=”max-height: 800px”> (remove tabindex=”-1″ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)