aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/jquery/exists.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/jquery/exists.js')
-rw-r--r--core/src/jquery/exists.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/src/jquery/exists.js b/core/src/jquery/exists.js
new file mode 100644
index 00000000000..8a8efdb5a63
--- /dev/null
+++ b/core/src/jquery/exists.js
@@ -0,0 +1,17 @@
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import $ from 'jquery'
+
+/**
+ * check if an element exists.
+ * allows you to write if ($('#myid').exists()) to increase readability
+ *
+ * @see {@link http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery}
+ * @return {boolean}
+ */
+$.fn.exists = function() {
+ return this.length > 0
+}