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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:44:52+00:00 2026-06-06T16:44:52+00:00

i cant access clicked object(this) parent’s class.. click same elements and different returns? this

  • 0

i cant access clicked object(this) parent’s class..
click same elements and different returns?

this is DEMO

HTML

<div class="rows row1">
  <div class="ele">1</div>
  <div class="ele">1</div>
  <div class="ele">1</div>
</div>

<div class="rows row2">
  <div class="ele">2</div>
  <div class="ele">2</div>
  <div class="ele">2</div>
</div>

jQuery

$('.ele').click(function() {

  if ( $(this).parent().hasClass('r1') ) {//way1
    alert('you clicked 1st row element');
  }

  else if ( $(this).parent().hasClass('r2') === true ) {//both way wont work
    alert('you clicked 2nd row element');
  }

});

​

  • 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-06-06T16:44:54+00:00Added an answer on June 6, 2026 at 4:44 pm

    Because both parent have no r1 or r2 class, that should be row1 and row2:

    $('.ele').click(function() {
    
      if ( $(this).parent().hasClass('row1') ) {
        alert('you clicked 1st row element');
      }
    
      else if ( $(this).parent().hasClass('row2')) {
        alert('you clicked 2nd row element');
      }
    
    });
    

    demo here

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

Sidebar

Related Questions

When a class is customized, by using its outlet , you cant access its
I can't solve this on MS Access SQL. I have a foo table with
I have a GUI architecture wherein elements fire events like so: guiManager->fireEvent(BUTTON_CLICKED, this); Every
i want to have access to LinqToSqlClasses (mydbDataContext) class from another solution project. in
I'm using a piece of JS twice for two, different yet the same, events.
I'm letting my users write their own HTML from my webpage. When they click
I can't access my model's attributes in the after_create callback... seems like I should
I've just installed Magento on my website, but I can't access the backend. The
When I run my cap deploy, it complains that it can't access the log
ArrayBuffer extends ResizableArray which include a protected method, swap. Yet I can't access swap.

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.