0

I am running the following but it is giving all the lists:

if($($wikiDOM.find('.infobox .location').length )) {
  $("#results").append("<li>" + $wikiDOM.find('.infobox .location').text() + "</li>");
}

United States
undefined
United States
undefined
undefined
undefined
undefined

I'd only need the ones with a location not undefined.

rob.m
  • 9,843
  • 19
  • 73
  • 162
  • 1
    Possible duplicate of [Is there an "exists" function for jQuery?](https://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery) – P.S. Jul 23 '17 at 17:10
  • @CommercialSuicide I did see few answers, I am not sure if the issue is that in my case I first need to `.find` then check if it exists and I am doing it wrong, as you can see on my code I am using `length` as they suggest – rob.m Jul 23 '17 at 17:12
  • @CommercialSuicide changed the question title to make it more unique – rob.m Jul 23 '17 at 17:13

1 Answers1

2
if($($wikiDOM.find('.infobox .location').length )) {

should be

if($wikiDOM.find('.infobox .location').length) {

(no need to push that length-value into a jquery-object)

Peter van der Wal
  • 11,141
  • 2
  • 21
  • 29