Created
February 19, 2018 20:34
-
-
Save PocketNinjaDesign/a183946d072fcbf45466e795bc1be173 to your computer and use it in GitHub Desktop.
jqlite most basic way of getting element from data retrieved with ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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