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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:07:25+00:00 2026-05-24T18:07:25+00:00

var classes = $(this).attr(‘class’).split(‘ ‘); // this gets the current element classes var classes

  • 0
var classes = $(this).attr('class').split(' '); // this gets the current element classes

var classes = $(this).parent().attr('class').split(' '); // this gets the parent classes.

The parent in the above situation is an ankor.

If I wanted to get the first parent DIV of $(this) what would the code look like?

var classes = $(this).div:parent().attr('class').split(' '); // just a quick try.

* Basically I want to get the classes of the first parent DIV of $(this).

thx

  • 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-24T18:07:25+00:00Added an answer on May 24, 2026 at 6:07 pm

    Use .closest() to traverse up the DOM tree up to the specified selector.

    var classes = $(this).parent().closest('div').attr('class').split(' '); // this gets the parent classes.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thought I understood how classes work, then I tried this code: class user {
Consider this code: var Someclass = new Class(); var Anotherclass = new Class(); var
I have following jQuery code $('a.editpo, a.resetpass').click(function(event){ event.preventDefault(); var urlToCall = $(this).attr('href'); var hyperlinkid
var localFile = Components.classes[@mozilla.org/filelocal;1].createInstance(Components.interfaces.nsILocalFile); localFile.initWithPath(C:\Windows\system32\cmd.exe); var process = Components.classes[@mozilla.org/processutil;1].createInstance(Components.interfaces.nsIProcess); process.init(localFile); var args=null; process.run(false, args,
function sc_HTMLParser(aHTMLString){ var parseDOM = content.document.createElement('div'); parseDOM.appendChild(Components.classes['@mozilla.org/feed-unescapehtml;1'] .getService(Components.interfaces.nsIScriptableUnescapeHTML) .parseFragment(aHTMLString, false, null, parseDOM)); return parseDOM;
var i : integer; i := 1234567; Given the above, I want the string
I'm using this bit of jQ to add a class to two different elements
I have some code like this: if (condition) { var variable = blah; }
I have a wrapped set like this: var $anchors = $('a'); I then do
I have an website with URL`s like example.com/index.php?p=home An this script $(document).ready(function() { var

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.