10 examples of 'javascript check if element exists' in JavaScript

Every line of 'javascript check if element exists' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
141function isVisible(element_id) {
142 var elm = document.getElementById(element_id);
143
144 return elm && elm.style.display != "none";
145}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

8function checkInputElement(elementId) {
9 var element = document.getElementById(elementId);
10 return element == null || (element.value || '') !== '';
11}
66checkElementId(element, index: number) {
67 return element.id === `${this.workflow.settings.itemIdPrefix}${index}`;
68}
20function doesElementExist(selector: string): boolean {
21 return fixture.debugElement.queryAll(By.css(selector)).length > 0;
22}
87function check_validation(element_id)
88{
89 if(!($(element_id).val()))
90 {
91 $(element_id).parent().parent().parent().addClass("errors");
92 $(element_id).parent().parent().parent().children('ul').show();
93 $("#errornote").show();
94 return true;
95 }
96 else
97 return false;
98}
10elementTagExists(tag : string) {
11 return element(by.tagName(tag)).isPresent();
12}
218_selector_exists() {
219 return $(this.chart_selector).length > 0;
220}
1function jsCheck(id)
2{
3 el=document.getElementById(id);
4 el.checked='checked';
5}
247function elementByCssExists(selector, delay = 2000) {
248 return driver.waitForElementByCss(selector, delay)
249 .should.eventually.exist;
250}
11async elementExists(selector, frameId = 0) {
12 // console.log(`check for ${selector} in tab ${this.id}, frame ${frameId}`);
13 return browser.tabs.sendMessage(this.id, {
14 type: 'elemExists',
15 selector,
16 }, {
17 frameId,
18 });
19}

Related snippets