jQuery callback on image load (even when the image is cached)

If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete, like this: $(“img”).one(“load”, function() { // do stuff }).each(function() { if(this.complete) { $(this).load(); // For jQuery < … Read more

jQuery select all except first

$(“div.test:not(:first)”).hide(); or: $(“div.test:not(:eq(0))”).hide(); or: $(“div.test”).not(“:eq(0)”).hide(); or: $(“div.test:gt(0)”).hide(); or: (as per @Jordan Lev’s comment): $(“div.test”).slice(1).hide(); and so on. See: http://api.jquery.com/first-selector/ http://api.jquery.com/not-selector/ http://api.jquery.com/gt-selector/ https://api.jquery.com/slice/

Check, using jQuery, if an element is ‘display:none’ or block on click

You can use :visible for visible elements and :hidden to find out hidden elements. This hidden elements have display attribute set to none. hiddenElements = $(‘:hidden’); visibleElements = $(‘:visible’); To check particular element. if($(‘#yourID:visible’).length == 0) { } Elements are considered visible if they consume space in the document. Visible elements have a width or … Read more

jQuery – Detect value change on hidden input field

So this is way late, but I’ve discovered an answer, in case it becomes useful to anyone who comes across this thread. Changes in value to hidden elements don’t automatically fire the .change() event. So, wherever it is that you’re setting that value, you also have to tell jQuery to trigger it. function setUserID(myValue) { … Read more

How can I remove the search bar and footer added by the jQuery DataTables plugin?

For DataTables >=1.10, use: $(‘table’).dataTable({searching: false, paging: false, info: false}); If you still want to be able the .search() function of this plugin, you will need to “hide” the search bar html with the dom setting: $(‘table’).dataTable({dom: ‘lrt’}); The defaults are lfrtip or <“H”lfr>t<“F”ip> (when jQueryUI is true), f char represents the filter (search) html … Read more

Confirm deletion in modal / dialog using Twitter Bootstrap?

GET recipe For this task you can use already available plugins and bootstrap extensions. Or you can make your own confirmation popup with just 3 lines of code. Check it out. Say we have this links (note data-href instead of href) or buttons that we want to have delete confirmation for: <a href=”#” data-href=”delete.php?id=23″ data-toggle=”modal” … Read more

How to change options of with jQuery?

You can remove the existing options by using the empty method, and then add your new options: var option = $(‘<option></option>’).attr(“value”, “option value”).text(“Text”); $(“#selectId”).empty().append(option); If you have your new options in an object you can: var newOptions = {“Option 1”: “value1”, “Option 2”: “value2”, “Option 3”: “value3” }; var $el = $(“#selectId”); $el.empty(); // remove … Read more

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