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

Live search through table rows

I’m not sure how efficient this is but this works: $(“#search”).on(“keyup”, function() { var value = $(this).val(); $(“table tr”).each(function(index) { if (index != 0) { $row = $(this); var id = $row.find(“td:first”).text(); if (id.indexOf(value) != 0) { $(this).hide(); } else { $(this).show(); } } }); });​ DEMO – Live search on table I did add … Read more

Free JSON formatted stock quote API (live or historical) [closed]

Check the following they are free, they generate Json, though for different exchanges you need to ensure that correct syntax is used. even Yahoo finance works well, but it has some issues regarding NSE and BSE data, which is always generated Null DEPRECATEDGoogle Finance – NSE URL – http://www.google.com/finance/info?q=NSE:AIAENG,ATULAUTO,<Add more NSE codes> DEPRECATED Google Finance … Read more

jQuery: live() vs delegate()

.live() requires you run the selector immediately, unless you’re using the result it’s very wasteful. The event handler here is attached to document, so all event of that type from any elements bubbling must be checked. Here’s a usage example: $(“.myClass”).live(“click”, function() { alert(“Hi”); }); Note that the statement $(“.myClass”) ran that selector to find … Read more

.live() vs .bind() [duplicate]

The main difference is that live will work also for the elements that will be created after the page has been loaded (i.e. by your javascript code), while bind will only bind event handlers for currently existing items. // BIND example $(‘div’).bind(‘mouseover’, doSomething); // this new div WILL NOT HAVE mouseover event handler registered $(‘<div/>’).appendTo(‘div:last’); … Read more

jquery .live(‘click’) vs .click()

There might be times when you explicitly want to only assign the click handler to objects which already exist, and handle new objects differently. But more commonly, live doesn’t always work. It doesn’t work with chained jQuery statements such as: $(this).children().live(‘click’,doSomething); It needs a selector to work properly because of the way events bubble up … Read more

tech