$(”) vs $(”) in jQuery

There is no difference, as seen in the source code, line 30 & line 121: /* Line 30*/ rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, /* Line 121 */ // If a single string is passed in and it’s a single tag // just do a createElement and skip the rest ret = rsingleTag.exec( selector ); The following are … Read more

Jquery – Perform callback after append

jQuery’s .each() takes a callback function and applies it to each element in the jQuery object. Imagine something like this: $(‘a.ui-icon-cart’).click(function(){ $(this).closest(‘li’).clone().appendTo(‘#cart ul’).each(function() { $(this).find(‘h5’).remove(); $(this).find(‘img’).css({‘height’:’40px’, ‘width’:’40px’}); $(this).find(‘li’).css({‘height’:’60px’, ‘width’:’40px’}); }); }); You could also just store the result and work on it instead: $(‘a.ui-icon-cart’).click(function(){ var $new = $(this).closest(‘li’).clone().appendTo(‘#cart ul’) $new.find(‘h5’).remove(); $new.find(‘img’).css({‘height’:’40px’, ‘width’:’40px’}); $new.find(‘li’).css({‘height’:’60px’, ‘width’:’40px’}); }); … Read more

jQuery: loading css on demand + callback if done

How to load multiple CSS files with callback as requested Note: ithout xdomain permissions, $.get will only load local files WORKING DEMO Note that the text “all css loaded” appears after loading but before the CSS is applied. Perhaps another workaround is required to overcome that. $.extend({ getManyCss: function(urls, callback, nocache){ if (typeof nocache==’undefined’) nocache=false; … Read more

jquery .on() method with load event

Refer to http://api.jquery.com/on/ It says In all browsers, the load, scroll, and error events (e.g., on an <img> element) do not bubble. In Internet Explorer 8 and lower, the paste and reset events do not bubble. Such events are not supported for use with delegation, but they can be used when the event handler is … Read more

Custom sorting on values in a data-sort attribute with Jquery Datatables

You can use data-order attr, for example <table class=”table table-bordered table-hover”> <thead> <tr> <th>Date</th> <th>Count</th> </tr> </thead> <tbody> <?php $count = 0; foreach($users as $user) {?> <tr> <td data-order=”<?php echo $count ?>”> <?php echo $user[‘createdDate’]; ?> </td> <td> <?php echo $user[‘count’]; ?> </td> </tr> <?php $count++; }?> <tr> <td data-order=”999999999999999999999999999″> <!–always last–> Total </td> <td> … Read more

jqGrid dynamic column binding

Try this in document.ready: $.ajax( { type: “POST”, url: “SomeUrl/GetColumnsAndData”, data: “”, dataType: “json”, success: function(result) { colD = result.colData; colN = result.colNames; colM = result.colModel; jQuery(“#list”).jqGrid({ jsonReader : { cell: “”, id: “0” }, url: ‘SomeUrl/Getdata’, datatype: ‘jsonstring’, mtype: ‘POST’, datastr : colD, colNames:colN, colModel :colM, pager: jQuery(‘#pager’), rowNum: 5, rowList: [5, 10, 20, … Read more

Concatenate in jQuery Selector

There is nothing wrong with syntax of $(‘#part’ + number).html(text); jQuery accepts a String (usually a CSS Selector) or a DOM Node as parameter to create a jQuery Object. In your case you should pass a String to $() that is $(<a string>) Make sure you have access to the variables number and text. To … Read more