Wednesday, 17 April 2019

Check if obect is jQuery wrapper











I need something like:



function func(obj) {
if (!$.isJQ(obj)) {

obj = $(obj);
}
// ...
}


Is there any isJQ function in jQuery?


Answer



You can use the instanceof operator:




obj instanceof jQuery


So, your code goes like :



function func(obj) {
if (!(obj instanceof jQuery)) {
obj = $(obj);
}
// ...

}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...