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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:45:05+00:00 2026-06-06T00:45:05+00:00

I have a div tag which looks something like this: <div id=some id here

  • 0

I have a div tag which looks something like this:

<div id="some id here" class="portlet portlet_15 portlet_content_15 new" >some content here</div>

I understand that I can get the id of this div using jquery like this:

$(this).closest("div").attr("id")

But how do I extract just the portlet_15 from the above class where 15 could be any number?

Here is an extract of the code showing where I am currently getting and sending off the id of the div:

$.ajax({
    url: 'some web service,
    type: 'POST',
    data: { strID:$(that).closest("div").attr("id"), strClass:"need to send the class value too right here, in this case it would be portlet_15" },
    error: function(xhr, status, error) {
        //some error message;
    },
    success: function() {
        //some success task
    }
});

I have included a note in the data part of the code above where the class should go.

  • 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-06T00:45:07+00:00Added an answer on June 6, 2026 at 12:45 am

    Your existing code is a bit confusing, since you don’t tell what this refers to. If it refers to your particular div element, then using closest isn’t correct because that already traverses up the DOM hierarchy.

    But otherwise if you’d like to get all those CSS classes of a particular element, this is what you have to call:

    $(this).attr("class").split(" ");
    // in your case this would return an array of classes:
    // ["portlet", "portlet_15", "portlet_content_15", "new"]
    

    this of course refers to the element in question. Then you can easily parse individual classes the way that you like. If you’d like to extract the number out, you’ll likely use a regular expression:

    /portlet_(\d+)/i;
    

    Use data- attributes

    But as others suggested, getting data across would be much better if you’d do that using data-attributes as in:

    <div id="some id here"
         class="portlet new"
         data-portlet="15"
         data-portlet-content="15">
             some content here
    </div>
    

    in this case both portlet-related classes are provided as data attributes, that you can easily access using:

    $(this).data("portlet"); // would return 15
    $(this).data("portletContent"); // would return 15
    $(this).data("portlet-content"); // would return 15
    

    The last two are variation of accessing the same data attribute with a hyphen’d name.

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

Sidebar

Related Questions

I have created a new tag by jQuery, and the code looks like this:
I have this code which can display drop down in div tag of html.
I have a every common page a.html which looks like this: <html> <head> <script
I have an input box which is present inside a Div tag. My issue
For example, I have the following tag which its content is short <div>It is
i have image set div tag like below <div style=width: 600px; background: #CCC;padding: 50px;
I have a scrollable div tag (overflow). Now I'd like to use mouse to
I have created a simple layout using the HTML div tag. I would like
Suppose I have an HTML snippet like this: <div> Hello <strong>There</strong> <div>I think <em>I
The some part of the html of the webpage which I'm testing looks like

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.