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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:56:30+00:00 2026-06-08T10:56:30+00:00

I am adding a class to the clicked element and getting the innerHTML of

  • 0

I am adding a class to the clicked element and getting the innerHTML of it, if the clicked element is a container. But if it is a HTML element and not a container,
For eg., if the clicked element is an image <img src="hello.png" />(which is not a container and cannot use innerHTML), then i need to get the corresponding element tag, i.e. i need to get <img src="hello.png" />. So anyway to do this with pure JavaScript?

P.S. I don’t want to use any JavaScript libraries here.

  • 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-08T10:56:32+00:00Added an answer on June 8, 2026 at 10:56 am

    You can do it like this…

    <img src="hello.png" onclick="alert(outerHTML)" />
    

    Note that outerHTML only recently gained Firefox support.

    This may look odd, but it does work.

    DEMO: http://jsfiddle.net/2GLjC/

    If you use a different type of handler (not inline), you could still use outerHTML from the context of the element.


    A cross-browser solution to pick up more Firefox support could look like this…

    function getOuterHTML(elem) {
        return elem.outerHTML || document.createElement("div")
                                         .appendChild(elem.cloneNode(true))
                                         .parentNode
                                         .innerHTML
    }
    

    So just pass your element to the getOuterHTML function, and it should return a correct result.

    alert(getOuterHTML(this));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello all i'm turning objects on (adding the class .active) and off on a
I have the following JQuery statement and it is adding the class 'current' but
Jquery Removing & Adding 'Active' Class On LI Navigation Works With preventDefault, But Link
Is there any possible way of adding class and id attributes in form_dropdown of
I'm adding a class on hover to various links, works great. However, when you
im having troubles with adding a class to the last option from foreach, its
I'm have some issues adding a class to 2 navigation links on a theme.
IE7 doesn't support :last-child pseudo selector. I am thinking of explicitly adding a class
I'm adding a style class to an node if it's selected and then remove
Does making the below class final (adding public final class) have any real impact

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.