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

  • Home
  • SEARCH
  • 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 304519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:17:17+00:00 2026-05-12T07:17:17+00:00

Some elements in my page are rendered through php code. Sometimes, on link clicks

  • 0

Some elements in my page are rendered through php code. Sometimes, on link clicks that redirect to a page in the same site, I want to insert html elements like div, span etc through javascript in their respective places. My main question is: how do I insert the elements in the appropriate place, and apply the same css styles to them as they would have if they had been inserted through normal flow like php or html code.

For example, suppose I need to insert a div element, which has a span element and an image element inside it, inside a container that has the other elements with the same structure:

<div class="container"><div><span></span><img /></div>...<div><span></span><img /></div> </div>  .  

I want to apply same style rules to my inserted elements as there are for other elements. That is, the inserted

<div><span></span><img /></div>

should have the same styles applied as

<style>

.container div {…}
.container div span {…}
.container div img{…}

But I dont want to manually compute the styles and then add those styles in jquery. How do I do this. The second part of this question is: suppose there are conditional styles applied depending on the browser. Now, how do I apply the conditional styles depending on the browser, without trying to do it manually?

  • 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-12T07:17:18+00:00Added an answer on May 12, 2026 at 7:17 am

    If you create your element using jQuery, simply use addClass() to add the container class to the parent <div> as such:

    var new_div = $('<div/>').addClass('container');
    // or (whatever floats your boat)
    var new_div = $(document.createElement('div')).addClass('container');
    

    It will then be styled as any other div.container on your page.

    If you are getting your elements via AJAX, make sure that the HTML you are sending already have the class applied.

    If you are simply adding elements inside your <div class="container"> via jQuery, they automatically follow the same style as the rest of the elements based on the markup you posted without any added code.

    // The inserted elements automatically follows the rules
    // in the internal and external stylesheet.
    var container = $('div.container:first').append('<div><span></span><img /></div>');
    

    It does not however automatically copy inline styles. Those should be moved to either an internal or external style-sheet.

    Personally, I find that inline styles are usually code-smells unless used for last-minute width and height purposes in variable-size boxes situations.

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

Sidebar

Ask A Question

Stats

  • Questions 190k
  • Answers 190k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's a little hackish, sure, but it's the best solution… May 12, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer Alternately select count(*) from groupmembers where user=@user1 and groupid in… May 12, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer Here is a (slow) implementation of the inverse cdf method… May 12, 2026 at 6:00 pm

Related Questions

I have a page which is largely created by DOM script, which generates a
I'm using KML and the GGeoXml object to overlay some shapes on an embedded
I'm trying to set background colours on a few different elements in an html
I've seen this on nerd dinner and other sites. On page load (in JavaScript,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.