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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:09:02+00:00 2026-06-12T22:09:02+00:00

Say, an HTML file contains the following elements: <div class=mydiv> <img src=img.jpg/> </div> I

  • 0

Say, an HTML file contains the following elements:

<div class="mydiv">  
    <img src="img.jpg"/>  
</div> 

I would like to know if it is safe to programmatically transform it into

<img class="mydiv" src="img.jpg" />  

That is, adding the parent’s class to the child element and ripping the parent itself.
Do the two versions of HTML code yield the same rendering when a CSS rule is present for the class? If not, which are the cases when it does not happen in fact?

Notes:
-the parent just features the class, it has no other meaningful attributes
-the CSS files cannot be altered
-the transformation is performed by javascript after the HTML is loaded
-the goal is getting rid of the parent but so that all CSS rules render the same

  • 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-12T22:09:05+00:00Added an answer on June 12, 2026 at 10:09 pm

    Addressing the title of the question first: classes are never inherited. CSS rules can be.

    There are a couple of general cases where things could go wrong.

    There might be rules which only apply under certain conditions (e.g. margin: auto has different effects depending on the value of display (which has different defaults for different elements).

    Selectors might be more specific that .mydiv. There might be div.mydiv or .mydiv img

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

Sidebar

Related Questions

Say I have a portion of my HTML file that looks like this: <div
Ok lets say i have an html file like this . . . <div
Let's say I'm including a file which contains html. The html have characters as
Say a user visits the page http://somedomain.com/path/file.html#foo , I'd like to display, using JavaScript,
Let's say I have a text file. It contains harmfull code like: <?php phpinfo();
Let us say I have a HTML page that contains a javascript file: The
Say i have a .html file that contains a web design and has variables
let's say I have HTML stored in HTMLElement object. It's outerHTML property looks like
Say I had the following HTML: <h2>Heading <span></span></h2> <ul> <li><a href=# title=I am wanting
lets say i have two pages links.html & contents.php ... first page contains only

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.