Skip to main content
deleted 3 characters in body
Source Link
René
  • 6.1k
  • 4
  • 24
  • 41

How can I check the existence of an element in jQuery?

The current code that I have is this:

if ($(selector).length > 0) {
    // Do something
}

Is there is a more elegant way to approach this? Perhaps a plugin or a function?

How can I check the existence of an element in jQuery?

The current code that I have is this:

if ($(selector).length > 0) {
    // Do something
}

Is there is a more elegant way to approach this? Perhaps a plugin or a function?

How can I check the existence of an element in jQuery?

The current code that I have is this:

if ($(selector).length > 0) {
    // Do something
}

Is there a more elegant way to approach this? Perhaps a plugin or a function?

added 2 characters in body
Source Link
Andrii Abramov
  • 10.5k
  • 12
  • 79
  • 101

How can I check the existence of an element in jQuery?

The current code that I have is this:

if ($(selector).length>0length > 0) {
    // Do something
}

Is there is a more elegant way to approach this? Perhaps a plugin or a function?

How can I check the existence of an element in jQuery?

The current code that I have is this:

if ($(selector).length>0) {
    // Do something
}

Is there is a more elegant way to approach this? Perhaps a plugin or a function?

How can I check the existence of an element in jQuery?

The current code that I have is this:

if ($(selector).length > 0) {
    // Do something
}

Is there is a more elegant way to approach this? Perhaps a plugin or a function?

edited tags
Link
John Slegers
  • 46.5k
  • 22
  • 202
  • 170
This question encompasses jQuery specifically, not JavaScript.
Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
edited tags
Link
Derek 朕會功夫
  • 93.7k
  • 44
  • 190
  • 251
Loading
edited tags
Link
Daniel A. White
  • 189.8k
  • 49
  • 368
  • 453
Loading
Jeopardy compliance.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132
Loading
Question Protected by Andrew Barber
added 1 characters in body; edited title
Source Link
bluish
  • 27k
  • 28
  • 123
  • 183
Loading
edited tags
Link
random
  • 9.9k
  • 10
  • 68
  • 84
Loading
edited tags
Link
Jake McGraw
  • 56k
  • 10
  • 50
  • 63
Loading
edited tags
Link
Rob Cooper
  • 28.8k
  • 26
  • 104
  • 142
Loading
Source Link
Jake McGraw
  • 56k
  • 10
  • 50
  • 63
Loading