Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6979491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:53:38+00:00 2026-05-27T17:53:38+00:00

I have an element called link which I need to check. Currently I’m doing

  • 0

I have an element called link which I need to check.

Currently I’m doing this:

// routine
if ( link.length == 1 && !link.is( ".toggle_popover" ) ) {
    self.panelTrans();
    } 

I’m curious regarding my check for link

I have tried the following:

if (link) ... 
if (!link)...
if (link.length == 1) ...
if (link.length != 0) ...

The problem is link can also be an empty object = [], in which case I don’t want my routine to fire.

Which way is best to do this? Right now I’m sticking with link.length == 1

Thanks for help!

UPDATE

link is the following:

var link = $( self.findClosestLink(event.target) )

findClosestLink: function (ele) {
      var self = this;
      while (ele){
          if (ele.nodeName.toLowerCase() == "a"){
              break;
              }
           ele = ele.parentNode;
           }
      return ele;
      }

It’s taken from the jQuery Mobile script and checks when the user clicks on screen if there is a parent link element. I’m using this to fire my own routine along JQM and want to make sure I’m not triggering any wasted function call. That’s why I’m checking for link. On Firebug I sometimes ended up with the function being triggered on an empty object [], which I do not want it to fire on.

Therefore my question on how to check for link

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:53:38+00:00Added an answer on May 27, 2026 at 5:53 pm

    i think that the best way is (i suppose you are speaking of a jQuery object)

    var link = $('#link');
    
    link.length === 1
    

    with an added = so there is no type coercion. If you use an id selector this is perfect as the selector returns only one element (this of course implies that your ids are unique on your page).
    if you must check if at least one element exist in a collection (You use a class selector) of course use

    collection.length > 0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have an element called #container-main . How do I make that display:none
I have an element for my side bar navigation being called from my layouts/default.ctp
I have a data.frame in R; it's called p . Each element in the
I have an element which may contain very big amounts of data, but I
I have a link appended to a div element. And on clicking the link,
I have a link for menu profile. It has a class called 'user-button'. When
I need help with binding back after I unbind an element. Basically, I have
I've got a canvas within which I have a list. The renderer for this
I have recently found out that there exists a method called nth_element in the
I load content via Ajax and then I'll have element like $('.my_content_class') and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.