Skip to content
Fix Code Error

Check if element exists in jQuery

March 13, 2021 by Code Error
Posted By: Anonymous

How do I check if an element exists if the element is created by .append() method?
$('elemId').length doesn’t work for me.

Solution

$('elemId').length doesn’t work for
me.

You need to put # before element id:

$('#elemId').length
---^

With vanilla JavaScript, you don’t need the hash (#) e.g. document.getElementById('id_here') , however when using jQuery, you do need to put hash to target elements based on id just like CSS.

Answered By: Anonymous

Related Articles

  • How do i update a javascript variable as its value changes?
  • Show/hide 'div' using JavaScript
  • GLYPHICONS - bootstrap icon font hex value
  • Javascript validate all checkboxes are selected
  • Why doesnt my table sort my div variable in numerical order?
  • how to use canvas in JavaScript flappy bird code
  • How to create a game over screen for a basic HTML/JS game?
  • Avoid using document.getElementById with Backbone.js
  • Disabling a button upon condition in Google App script
  • Reduce vs Collect method on Parallel Streams vs…
  • What does this symbol mean in JavaScript?
  • Is it possible to apply CSS to half of a character?
  • Fundamental difference between Hashing and…
  • setTimeout function not working : javascript
  • How to use html template with vue.js
  • jQuery Mobile: document ready vs. page events
  • How to use Servlets and Ajax?
  • Js Calculation based on radio button, and some problems
  • Setting DIV width and height in JavaScript
  • why preventdefault/stopPropagation not working in…
  • Using `window.location.hash.includes` throws “Object…
  • javascript minesweeper issue with revealing tiles…
  • Downloading jQuery UI CSS from Google's CDN
  • Generated row of table event listener not working instantly
  • Displaying the Dates that user have chosen from date input
  • How do I keep only the first map and when the game…
  • JavaScript TypeError: Cannot read property 'style' of null
  • I made a game it should display two images when i…
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • How to use java.net.URLConnection to fire and handle…
  • How to add to an existing hash in Ruby
  • Getting a "TypeError" when trying to validate a form
  • during wct test: Failed to load resource: the server…
  • Javascript text animation not triggering
  • Flappy bird code not working - JavaScript
  • Multiple items from DropDownList with protected sheet
  • Specifying java version in maven - differences…
  • Simple pagination in javascript
  • Using setInterval for creating animation
  • backbone.js collection adds empty element when created?
  • How can I change an element's class with JavaScript?
  • Javascript change color of text and background to…
  • Web components and JS DOM Elements with a placeholder
  • How can I center all my contents in html?
  • load scripts asynchronously
  • JS file is not updating to new id values
  • Having trouble with my nav bar/header, It used to…
  • How to add fade animation for this tab
  • Finding all possible combinations of numbers to…
  • Sort table rows In Bootstrap
  • I'm trying to take inputs from an HTML form and pass…
  • jQuery .each() index?
  • How to limit the number of total animated drop cubes…
  • Trying to keep dropdown menus flush to the edge of…
  • Am I paranoid? "Brutally" big Polymer website after…
  • Repeatedly Toggle Div Background Color On Click…
  • Ember.js - Using a Handlebars helper to detect that…
  • The definitive guide to form-based website authentication
  • Scraping Tables in Python Using Beautiful Soup…
  • Difference between RegisterStartupScript and…
  • What does AngularJS do better than jQuery?
  • showing record text with red color when click stop button
  • What is the JSF resource library for and how should…
  • JavaScript hashmap equivalent
  • "Access is denied" JavaScript error when trying to…
  • Error stopping function after alert message is shown
  • How to create multidimensional array
  • Change onclick action with a Javascript function
  • Import javascript file after component is mounted
  • Centering in CSS Grid
  • the order of functions js
  • How to loop through all the buttons to a click event…
  • Active tab issue on page load HTML
  • Style jQuery autocomplete in a Bootstrap input field
  • Jquery fadeToggle Trouble
  • How to unescape a Java string literal in Java?
  • "Thinking in AngularJS" if I have a jQuery background?
  • how can select from drop down menu and call…
  • After a little scroll, the sticky navbar just is not…
  • Load and execution sequence of a web page?
  • Polymer core-scaffold nav core-menu does not scroll
  • Cannot send array list from JavaScript to Django View
  • Click button copy to clipboard using jQuery
  • Problem with javascript and user-input on website to…
  • Identifying and solving…
  • Polymer 1.0 Trying to make a splitter which works…
  • Resource-efficient finding ONE possible combinations…
  • String variable interpolation Java
  • Navbar not filling width of page when reduced to mobile view
  • Form validation gets bypassed when I'm hitting the…
  • For-each over an array in JavaScript
  • How can I manually compile a svelte component down…
  • Ember-Data: My custom `serializeIntoHash` is…
  • How to Detect Browser Back Button event - Cross Browser
  • Fontawesome fonts not loading using Aurelia, with…
  • SHA512 vs. Blowfish and Bcrypt
  • Why does jQuery or a DOM method such as…
  • Don't let the user select a past date?
  • What does the CSS rule "clear: both" do?
  • I need help figuring out how to add values

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Does Java support default parameter values?

Next Post:

How to print a number with commas as thousands separators in JavaScript

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error