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 7522387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:30:27+00:00 2026-05-30T02:30:27+00:00

I need to check for an element with a css class being in existance

  • 0

I need to check for an element with a css class being in existance on my HTML. I’ve Googled and searched here, and the common answer is to use .length > 0.

But that doesn’t work. I’m getting an “Object expected” error. Any help greatly appreciated.

<script type="text/javascript">
  if ($(".deleteLink").length != 0) 
  {
    $(".deleteLink").click(function () { return confirm('some message?'); });
  }
</script>

.deleteLink is a css class that belongs to a tag that may or may not be present. I’m getting the error on the conditional part.

Am I missing somethign?? Because it seems that everyone says to use .length…

  • 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-30T02:30:29+00:00Added an answer on May 30, 2026 at 2:30 am

    Checking length is the correct way. There’s something else wrong with your code. Did you perhaps forget to include jQuery? Is something clobbering $? Run it in something better than IE to get a more meaningful error message.

    Also, a few tips. if ($(...).length) is enough because 0 is falsy, no need for the comparison. Also, you don’t need to check if elements exist before manipulating them with jQuery (if it’s something lightweight such as just attaching an event handler). Manipulating an empty jQuery result doesn’t do anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check the type of each element in an array... for(id obj
I need to check whether a page is being redirected or not without actually
Is there any way only using CSS (no script) to check if an element
I need to check with jQuery if a DIV element is not falling off-screen.
I need to check if a CSS rule exists because I want to issue
I need to check if each element in second list has 3 times more
<pre> <script> // here i want to check form validation //if i use for
I need to check whether document element value is changed after particular operation using
what I basically need is to check every element of a list and if
I need to check with jquery that a anchor element only has text in

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.