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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:48:04+00:00 2026-06-07T13:48:04+00:00

I am adding a class dynamically to some elements. And i need to get

  • 0

I am adding a class dynamically to some elements. And i need to get the innerHTML of the clicked element where the added class is present. Can anyone have any idea of how to get the innerhtml with refer to class?

Please note that i don’t want to use any Javascript libraries like jQuery.

  • 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-07T13:48:07+00:00Added an answer on June 7, 2026 at 1:48 pm

    Try this:

    document.body.onclick = function(e) {
        var clickedEl = window.event ? event.srcElement : e.target;
        while (clickedEl != null) {
            if (clickedEl.className
                && (" " + clickedEl.className + " ").indexOf(" yourclass ") != -1) {
                // do something, e.g.,
                alert("Element with class was clicked");
                return;
            }
            clickedEl = clickedEl.parentNode;
        }
    }​
    

    Demo: http://jsfiddle.net/3qChA/

    This will do “something” (in my example show an alert) when any element with class “yourclass” is clicked, or when any descendant element of an element with “yourclass” is clicked. Obviously you can replace the hard-coded “yourclass” with a variable as appropriate.

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

Sidebar

Related Questions

I'm have some issues adding a class to 2 navigation links on a theme.
I have a situation where I am dynamically adding some content to popup box
I have the following JQuery statement and it is adding the class 'current' but
Does making the below class final (adding public final class) have any real impact
I'm dynamically adding some li s to an unordered list using jQuery. They are
I am working on creating some grails domain objects dynamically and then adding them
In my app i have a ListView which dynamically increases by adding 10 items
I am working with a std::vector to hold some objects that have dynamically allocated
I have created a UIScrollView in a cocos2d application. I am adding sprites dynamically,
I am trying to add some dynamically (based on the URI) created class names

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.