CSS styling does not apply to HTML elements that are dynamically created using JavaScript

A script containing dynamic HTML content is sourced from an external website, injected by RSS feeds. To access the content directly, visit this link.

The script needs to be wrapped around HTML tags for front-end display. For example:

<div>http://feed.informer.com/widgets/J9HBCBNMTQ.js</div>

In order to avoid cluttering the HTML file with numerous scripts, you can use JavaScript to inject the script wrapped in a body tag. This way, new pages can be created on button clicks without creating separate HTML files.

By using JavaScript functions like page1(), page2(), and nextpage(), you can dynamically generate content based on user interaction.

CSS can also be used to hide specific divs within the script-generated content. However, there might be challenges when applying CSS externally or internally, as the divs (#text1, #text2, etc.) are part of the script's HTML content itself.

Answer №1

It's incredible to see that

location.replace('javascript:page' + page + '()')
actually works. I was able to hide images simply by moving the css into the returned html.

function page1() {
    return "<html><head><style>.heraldone #text2,.heraldone #text3,.heraldone #text4,.heraldone #text5 {display: none;}</style></head><body class='heraldone'><script src='http://feed.informer.com/widgets/J9HBCBNMTQ.js'><\/script><\/body><\/html>";
}

function page2() {
    return '<html><body>Hello world (2)</body></html>';
}

function nextpage(page) {
    if (!document.image) {
        location.replace('javascript:page' + page + '()');
    } else {
        location.href = 'javascript:page' + page + '()';
    }
}

I'm not sure what you're trying to achieve, but personally, I would have opted to replace the body content of the main html page instead of relying on whatever mysterious process is making this work correctly. This approach would result in smaller and more coherent html pages. For example, something like

var pages = ['<script ... />', 'Hello world']; document.getElementsByTagName('body')[0].innerHTML = pages[page-1];

Answer №2

The specific styles you mentioned (#text2 - ...5) are actually not found within the javascript code provided. The only relevant style defined for any of those #text elements is

#text3 {z-index: 2;position:absolute; margin-top: 50%;}

Therefore, it seems necessary to add these styles to the referenced js files since they are not included anywhere else.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to transform object into a primitive value using imported JSON data

https://i.sstatic.net/HcY5M.png I am currently working on creating a Vuetify component dynamically within a Nuxt project, as discussed in this Stack Overflow thread (Using different text values with Vuetify component). To achieve this, I am importing and ...

Replacing CSS using jQuery/JavaScript

Recently, I encountered a challenge with a table that had its border set as 1px solid silver from an external style sheet (a .css file over which I had no control). The CSS code responsible for styling the table was as follows: my_table tbody td { font: ...

Tips for setting discrete mapper style in cytoscapejs?

Currently, I am defining the style of cytoscape.js through CSS and converting it to JSON format using this resource. My goal is to implement a discrete mapper for styling. It's similar to the scenario discussed in How to use a descreteMapper like on c ...

Setting a TypeScript collection field within an object prior to sending an HTTP POST request

Encountered an issue while attempting to POST an Object (User). The error message appeared when structuring it as follows: Below is the model class used: export class User { userRoles: Set<UserRole>; id: number; } In my TypeScript file, I included ...

Utilizing JavaScript to Parse RSS XML Feeds Across Domains

Looking to parse an RSS (XML) file without relying on the Google RSS feed. I have attempted using JSONP, but it resulted in downloading the file and throwing an error "Uncaught SyntaxError: Unexpected token < ". $.ajax({ type: "GET", ur ...

Arranging Bootstrap 4 columns in a vertical stack

My HTML code is as follows: <html> <head> <title>Title</title> <meta charset="utf-8"> <meta name="description" content="description"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <li ...

How to identify the node with the appropriate date range attribute using JavaScript or jQuery

I am seeking assistance in using Javascript, preferably jQuery, to identify the specific "node" within an XML structure where a given date falls between its "begin" and "end" dates. XML EXAMPLE: <nodes> <node begin="2014-01-01" end="2014-01- ...

Implementing a Context Menu with a Single Click

I need assistance with creating a context menu that appears when the user clicks inside an HTML5 canvas. I want to have functions called when an item in the menu is selected. Can anyone provide guidance on how to achieve this? ...

flex display doesn't automatically wrap long strings as intended

Attempting to showcase a lineup of items in a row using flex display. Development is being done with angular 7. Check out the HTML code I utilized: <div class="d-flex"> <span>Other:&nbsp;</span> <div class="d-flex"> < ...

Unable to retrieve key value pairs of objects

Currently, I am utilizing FormData in my VueJS FrontEnd to send images to my Express Server for storage in a Mongo DB using gridfs-stream and mongoose. Despite the image objects successfully reaching the server, I am struggling to access their key-value pa ...

Concerns arise regarding the implementation of an image slider using HTML and CSS

Hey guys, I've created an image slider, but I'm facing an issue where the first click doesn't trigger a smooth animation. Instead, it jumps to the target without any transition. I want a seamless change of images, but right now it's jus ...

I encountered an issue where the error "data.map is not a function" occurs whenever I try to execute a React component

I have implemented the HorizontalScrollbar component and passed data as a prop. When I try to run the HorizontalScrollbar component, I encounter the following error in the console tab of Chrome: Error: Uncaught TypeError: data.map is not a function Horiz ...

Click on a specific button within a DataTable row

I am working with a dataTable that fetches data from the database using Jquery. In each row, there are two buttons for accepting or rejecting something. My goal is to make the accept button disappear when rejecting and vice versa. public function displayT ...

Organize your information starting from the left and moving to the right

Currently, I am engaged in a project where I need to retrieve commands and showcase them on a screen. However, there seems to be an issue as the commands are appearing one by one and automatically moving down to the footer. What I actually want is for th ...

Adding a logo to a website that utilizes CSS, HTML, JS, and Bootstrap

Hey there! I'm new to the world of Front-end development and I've been learning by watching videos and reading everything I can find on the Internet. Currently, I'm using HTML, CSS, and JS for my website. Can anyone help me figure out how to ...

What is the best way to extract data from an HTML string stored as a JSON value using Python?

I have a JSON file that contains the following data: { "entryLabel": "cat", "entryContent": "<div class=\"entry_container\"><div class=\"entry lang_en-gb\" id=\"cat_1\"><span class=\"inline\"& ...

Using jQuery to check if a value exists in a PHP array

I am encountering an issue with handling an array in PHP and using it in my jQuery code. Previously, I was able to successfully work with the array when it was a string, but now that it is more complex, the comparison of elements is not functioning properl ...

jQuery UI Sortable - Eliminate placeholder once item is has been dropped

Trying to implement a nested sortable feature, and while it's mostly working, there's one little issue bothering me. I'd like the placeholder to only disappear after I release the dragged item (on mouseup), but I'm struggling to achiev ...

Customize the antd theme in a create-react-app project without the need to eject webpack

Struggling with customizing antd in my react app. I'm hesitant to mess with the webpack config.js file since I'm not well-versed in webpack. My goal is to avoid having a site that looks like a generic antd clone, but all my attempts at customizat ...

Leverage the power of the YouTube API to determine if a video is able to be embedded

As I delve into the YouTube Data API v3 to determine if a particular video is embeddable, I have come across the status.embeddable property that seems crucial. By making a request like this: https://www.googleapis.com/youtube/v3/videos?id=63flkf3S1bE& ...