Angular 2 – innerHTML styling

I am getting chunks of HTML codes from HTTP calls. I put the HTML blocks in a variable and insert it on my page with [innerHTML] but I can not style the inserted HTML block. Does anyone have any suggestion how I might achieve this? @Component({ selector: ‘calendar’, template: ‘<div [innerHTML]=”calendar”></div>’, providers: [HomeService], styles: [`h3 … Read more

Show/hide ‘div’ using JavaScript

For a website I’m doing, I want to load one div, and hide another, then have two buttons that will toggle views between the div using JavaScript. This is my current code function replaceContentInContainer(target, source) { document.getElementById(target).innerHTML = document.getElementById(source).innerHTML; } function replaceContentInOtherContainer(replace_target, source) { document.getElementById(replace_target).innerHTML = document.getElementById(source).innerHTML; } <html> <button onClick=”replaceContentInContainer(‘target’, ‘replace_target’)”>View Portfolio</button> <button onClick=”replaceContentInOtherContainer(‘replace_target’, … Read more

Can scripts be inserted with innerHTML?

I tried to load some scripts into a page using innerHTML on a <div>. It appears that the script loads into the DOM, but it is never executed (at least in Firefox and Chrome). Is there a way to have scripts execute when inserting them with innerHTML? Sample code: <!DOCTYPE html> <html> <body onload=”document.getElementById(‘loader’).innerHTML = … Read more

React.js: Set innerHTML vs dangerouslySetInnerHTML

Is there any “behind the scenes” difference from setting an element’s innerHTML vs setting the dangerouslySetInnerHTML property on an element? Assume I’m properly sanitizing things for the sake of simplicity. Example: var test = React.createClass({ render: function(){ return ( <div contentEditable=”true” dangerouslySetInnerHTML={{ __html: “Hello” }}></div> ); } }); vs var test = React.createClass({ componentDidUpdate: function(prevProp, … Read more