Skip to content

Instantly share code, notes, and snippets.

@PocketNinjaDesign
Created February 19, 2018 20:34
Show Gist options
  • Save PocketNinjaDesign/a183946d072fcbf45466e795bc1be173 to your computer and use it in GitHub Desktop.
Save PocketNinjaDesign/a183946d072fcbf45466e795bc1be173 to your computer and use it in GitHub Desktop.
jqlite most basic way of getting element from data retrieved with ajax
// NOTE: This also uses another function created called findLite
// https://gist.github.com/PocketNinjaDesign/b7808126e97f319929674d09e4ac85d1
/**
* @example
* // returns jqlite object using class
* $.fn.findFromAjax(response.data, '.some-class-name');
* @example
* // returns jqlite object using id
* $.fn.findFromAjax(response.data, '.someId');
* @example
* // return jqlite object using element name
* $.fn.findFromAjax(response.data, 'span')
*
* @param {string} responseData Ajax data retreived
* @param {string} elementQuery element(s) to search for
* @description Returns a jqlite object from ajax data containing markup
*/
$.fn.findFromAjax = function(responseData, elementQuery) {
return $('<div />').html(responseData).findLite(elementQuery);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment