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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:51:56+00:00 2026-05-20T04:51:56+00:00

Aloha, I found an answer to my question here . Basically i’m looking to

  • 0

Aloha,

I found an answer to my question here. Basically i’m looking to tell if a tag has an attribute. I don’t care what the value is, just if there is one.

I’m currently using:

$.fn.hasAttr = function (attr) {
    var attribVal = this.attr(attr);
    alert(attr+" ["+attribVal+"]");
    return (attribVal !== undefined) && (attribVal !== false);
};

This function is not working in Opera or Webkit. It returns true even if the attribute does not exist. The alert that I added shows that the attribVal is equal to blank, not false, not undefined, not null, but blank. Firefox and IE this works fine in as attribVal is undefined.

The problem is I want it to return true for a blank attribute, if its on the tag and false for no attribute on the tag.

Edit:
expected results…

<tag />                    should be hasAttr('placeholder') = false
<tag placeholder />        should be hasAttr('placeholder') = true
<tag placeholder="" />     should be hasAttr('placeholder') = true
<tag placeholder="Hi" />   should be hasAttr('placeholder') = true

Edit: Current code

This works in WebKit and FF, not in IE or Opera.

Update After all this, my original code works, unless I am looking at the placeholder attribute. Opera and webkit return true for all four options when I’m looking at the placeholder attribute. See here for an example. I’ve updated my expected results to use the placeholder attribute.

  • 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-20T04:51:57+00:00Added an answer on May 20, 2026 at 4:51 am

    This should work in all browsers:

     $.fn.hasAttr = function (attr) {
         for (var i = 0; i < this[0].attributes.length; i++) {
             if (this[0].attributes[i].nodeName == attr) {return true}
         }
        return false;
     };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After looking for a good email validation routine, I found this answer to a
I found the answer to this, but it's a bit of a gotcha so
I found JPG does not support transparency, the alpha value is always 255. I
I did a search but I didn't found anything . I'm looking for a
EDIT Found the answer. It's a logical error located at if(carry == 0 &&
Trying to reproduce the problem from this question , I've found I can't plot
I have looked on here and found a few examples but nothing works so
Aloha, I've been following the guidelines here: http://developer.android.com/resources/tutorials/testing/helloandroid_test.html To create some simple test cases
So i have a problem. I found a cool old tv grain code (here
I've found a lot of information on autoresizing but none has been able to

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.